package com.sailfish.springbootdemo.service.db1;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sailfish.springbootdemo.common.DB1EmailTemplates;
import com.sailfish.springbootdemo.common.DeviceUseName;
import com.sailfish.springbootdemo.common.ProcessIdConfig;
import com.sailfish.springbootdemo.dao.db1.*;
import com.sailfish.springbootdemo.dao.db4.UserDao;
import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.*;
import com.sailfish.springbootdemo.pojo.db2.MailAddress;
import com.sailfish.springbootdemo.pojo.db4.Operate;
import com.sailfish.springbootdemo.pojo.db4.User;
import com.sailfish.springbootdemo.service.db2.ThirdApiService;
import com.sailfish.springbootdemo.service.db4.OperateService;
import com.sailfish.springbootdemo.utils.CommonUtils;
import com.sailfish.springbootdemo.utils.HttpUtil;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class CoreAlgorithmServiceImpl implements CoreAlgorithmService {

    @Value("${personal.config.apis.sign}")
    private String sign;

    @Autowired
    private PcbaLineDao pcbaLineDao;

    @Autowired
    private PcbaDeviceParamDao pcbaDeviceParamDao;

    @Autowired
    private TechDeviceParamDao techDeviceParamDao;

    @Autowired
    private BaseCapacityRuleDao baseCapacityRuleDao;

    @Autowired
    private TechCapacityRuleDao techCapacityRuleDao;

    @Autowired
    private LineBaseParamDao lineBaseParamDao;

    @Autowired
    private UserDao userDao;

    @Autowired
    private ThirdApiService thirdApiService;

    @Autowired
    private PcbaSpecialResourceDao pcbaSpecialResourceDao;

    @Autowired
    private AuditHistoryDao auditHistoryDao;

    @Autowired
    private PcbaDeviceResourceDao pcbaDeviceResourceDao;

    @Autowired
    private PcbaDeviceRelatedDeviceParamDao pcbaDeviceRelatedDeviceParamDao;

    @Autowired
    private PcbaDeviceRelatedTechParamDao pcbaDeviceRelatedTechParamDao;

    @Autowired
    private LineBaseBigTypeDao lineBaseBigTypeDao;

    @Autowired
    private LineBaseSmallTypeDao lineBaseSmallTypeDao;

    @Autowired
    private PcbaDeviceDao pcbaDeviceDao;

    @Autowired
    private PcbaProcessDao pcbaProcessDao;

    @Autowired
    private LineTechBigTypeDao lineTechBigTypeDao;

    @Autowired
    private LineTechSmallTypeDao lineTechSmallTypeDao;

    @Autowired
    private LineBaseCapacityValueDao lineBaseCapacityValueDao;

    @Autowired
    private RoadmapParamDao roadmapParamDao;

    @Autowired
    private LineTechCapacityValueDao lineTechCapacityValueDao;

    @Autowired
    private PcbaDeviceRelatedTechParamActualDao pcbaDeviceRelatedTechParamActualDao;

    @Autowired
    private UpkeepDao upkeepDao;

    @Autowired
    private LineLevelDao lineLevelDao;

    @Autowired
    private UpkeepHistoryDao upkeepHistoryDao;

    @Autowired
    private PcbaSpecialRelatedTechParamActualDao pcbaSpecialRelatedTechParamActualDao;

    @Autowired
    private MaintenanceConfigDao maintenanceConfigDao;

    @Value("${personal.config.apis.refresh-tou-chan-ping-gu-api}")
    private String refreshTouChanPingGuApi;

    @Value("${personal.config.apis.refresh-tou-chan-excel-api}")
    private String refreshTouChanExcelApi;

    @Autowired
    private OperateService operateService;

    @Autowired
    private PcbaCompanyDao pcbaCompanyDao;

    @Autowired
    private PcbaWorkshopDao pcbaWorkshopDao;

    private String operateSmallType = "级联改动";

    @Value("${personal.config.sso.trusted-redirect-uri}")
    private String trustedRedirectUri;

    @Qualifier("MysqlTransactionManager1")
    @Autowired
    private DataSourceTransactionManager transactionManager1;

    @Transactional(transactionManager = "MysqlTransactionManager1")
    @Override
    public Result calcLineBaseCapacity(Integer pcbaLineId) {
        try {
            if (pcbaLineId == null || "".equals(pcbaLineId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
            }

            Integer pressfitProcessId = ProcessIdConfig.PressfitProcessId;
            Integer aoiPressfitProcessId = ProcessIdConfig.AoiPressfitProcessId;

            PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
            if (pcbaLine != null) {
                //List<LineBaseParam> lineBaseParamList = lineBaseParamDao.getAllLineBaseParamByType("", null, null);
                List<BaseCapacityRule> baseCapacityRuleList = baseCapacityRuleDao.getAllBaseCapacityRule("", null, null);
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                List<Map<String, String>> deviceResourceIdList = new ArrayList<>();
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    Map<String, String> map = new HashMap<>();
                    map.put("deviceResourceId", (pcbaDevice.getPcbaDeviceResourceId() != null && !"".equals(pcbaDevice.getPcbaDeviceResourceId().toString())) ? pcbaDevice.getPcbaDeviceResourceId().toString() : "");
                    map.put("deviceUse", (pcbaDevice.getPurpose() != null && !"".equals(pcbaDevice.getPurpose())) ? pcbaDevice.getPurpose() : "");
                    deviceResourceIdList.add(map);
                }
                // System.out.println("deviceResourceIdList===");
                // System.out.println(deviceResourceIdList_);
                //Set<Integer> set_ = new HashSet<>(deviceResourceIdList_);
                //List<Integer> deviceResourceIdList = new ArrayList<>(set_);
                //List<Integer> deviceResourceIdList = deviceResourceIdList_;
                // System.out.println(deviceResourceIdList);
                List<BaseCapacityRule> finalKeyAndValueList = new ArrayList<>();
                // for (LineBaseParam lineBaseParam : lineBaseParamList) {
                for (BaseCapacityRule baseCapacityRule : baseCapacityRuleList) {
                    String lineBaseParamKey = baseCapacityRule.getLineBaseParamKey();
                    String lineBaseParamName = baseCapacityRule.getBaseCapacityRuleName();
                    Integer bigTypeId = baseCapacityRule.getLineBaseBigTypeId();
                    Integer smallTypeId = baseCapacityRule.getLineBaseSmallTypeId();
                    Integer valueFromOnline = baseCapacityRule.getValueFromOnline();
                    //System.out.println(lineBaseParam.getLineBaseParamName() + "：" + lineBaseParamKey);
//                    if("input_1690168363112".equals(lineBaseParamKey)){
//                        System.out.println("input_1690168363112");
//                    }
//                    if("input_1690168363101".equals(lineBaseParamKey)){
//                        System.out.println("input_1690168363101");
//                    }
//                    if("input_1704877797972".equals(lineBaseParamKey)){
//                        System.out.println("input_1704877797972");
//                    }

                    if (lineBaseParamKey != null && !"".equals(lineBaseParamKey)) {
                        //BaseCapacityRule baseCapacityRule = baseCapacityRuleDao.getBaseCapacityRuleByKey(lineBaseParamKey);
                        //if(baseCapacityRule != null){
                        String pcbaDeviceParamKeys = baseCapacityRule.getPcbaDeviceParamKeys();
                        String pcbaDeviceParamKeys2 = baseCapacityRule.getPcbaDeviceParamKeys2();
                        String pcbaDeviceUse = baseCapacityRule.getDeviceUse();
                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                            Integer baseCapacityRuleType = baseCapacityRule.getBaseCapacityRuleType();
                            if (baseCapacityRuleType != null && !"".equals(baseCapacityRuleType.toString())) {
                                /**
                                 * 1：取最大值
                                 * 2：取最小值
                                 * 3：取当前值
                                 * 4：取最小值[特殊，取前两位判断大小]
                                 * 5：取最大值[特殊，取前两位判断大小]
                                 * 6：取和值
                                 * 7：只要有一台为”是“，则为是；全部”否“，则为”否“
                                 * 8：只要任意一台填写”有“，则为”有“
                                 * 9：取第一个集合的最大值在和第二个集合取最小值
                                 */
                                if ("1".equals(baseCapacityRuleType.toString())) {
                                    //取最大值
                                    String finalValue1 = "";
                                    String finalValue2 = "";

                                    // 按照 先循环 key 找出最大值
                                    List<String> valueList = new ArrayList<>();
                                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                                        for (String s : keyArr) {
                                            //System.out.println("key：" + s);
                                            // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                            String currentValue = "";
                                            for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                            valueList.add(currentValue);
                                        }
                                    }
                                    if (valueList.size() == 0) {
                                        finalValue1 = "";
                                    } else {
                                        for (String s : valueList) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue1)) {
                                                    finalValue1 = s;
                                                } else {
                                                    if (Double.parseDouble(finalValue1) <= Double.parseDouble(s)) {
                                                        finalValue1 = s;
                                                    }
                                                }
                                            } else {
                                                if ("不限制".equals(s)) {
                                                    finalValue1 = "不限制";
                                                }
                                            }
                                        }
                                    }

                                    // 按照 先循环 设备资源id 找出最大值
                                    List<String> valueList2 = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        valueList2.add(currentValue);
                                    }
                                    if (valueList2.size() == 0) {
                                        finalValue2 = "";
                                    } else {
                                        for (String s : valueList2) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue2)) {
                                                    finalValue2 = s;
                                                } else {
                                                    if (Double.parseDouble(finalValue2) <= Double.parseDouble(s)) {
                                                        finalValue2 = s;
                                                    }
                                                }
                                            } else {
                                                if ("不限制".equals(s)) {
                                                    finalValue1 = "不限制";
                                                }
                                            }
                                        }
                                    }

                                    // 比较 finalValue1 和 finalValue2 取最大
                                    if ("不限制".equals(finalValue1)) {
                                        BaseCapacityRule l = new BaseCapacityRule();
                                        l.setBaseCapacityRuleName(lineBaseParamName);
                                        l.setLineBaseParamKey(lineBaseParamKey);
                                        l.setLineBaseParamValue("不限制");
                                        l.setLineBaseBigTypeId(bigTypeId);
                                        l.setLineBaseSmallTypeId(smallTypeId);
                                        l.setValueFromOnline(valueFromOnline);
                                        finalKeyAndValueList.add(l);
                                    } else {
                                        Double finalValue_1 = 0.0;
                                        Double finalValue_2 = 0.0;
                                        Double finalValue = 0.0;
                                        if (CommonUtils.isNumeric(finalValue1)) {
                                            finalValue_1 = Double.parseDouble(finalValue1);
                                        } else {
                                            finalValue_1 = 0.0;
                                        }
                                        if (CommonUtils.isNumeric(finalValue2)) {
                                            finalValue_2 = Double.parseDouble(finalValue2);
                                        } else {
                                            finalValue_2 = 0.0;
                                        }
                                        if (finalValue_1 >= finalValue_2) {
                                            finalValue = finalValue_1;
                                        } else {
                                            finalValue = finalValue_2;
                                        }

                                        BaseCapacityRule l = new BaseCapacityRule();
                                        l.setBaseCapacityRuleName(lineBaseParamName);
                                        l.setLineBaseParamKey(lineBaseParamKey);
                                        l.setLineBaseParamValue("0.0".equals(finalValue.toString()) ? "" : CommonUtils.removeZeros(finalValue.toString()));
                                        l.setLineBaseBigTypeId(bigTypeId);
                                        l.setLineBaseSmallTypeId(smallTypeId);
                                        l.setValueFromOnline(valueFromOnline);
                                        finalKeyAndValueList.add(l);
                                    }
                                    //System.out.println(lineBaseParam.getLineBaseParamName() + "：" + lineBaseParamKey + "：" + finalValue);
                                } else if ("2".equals(baseCapacityRuleType.toString())) {
                                    //取最小值
                                    String finalValue1 = "";
                                    String finalValue2 = "";

                                    // 按照 先循环 key 找出最大值
                                    List<String> valueList = new ArrayList<>();
                                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                                        for (String s : keyArr) {
                                            //System.out.println("key：" + s);
                                            // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                            String currentValue = "";
                                            for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                            valueList.add(currentValue);
                                        }
                                    }
                                    if (valueList.size() == 0) {
                                        finalValue1 = "";
                                    } else {
                                        for (String s : valueList) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue1)) {
                                                    finalValue1 = s;
                                                } else {
                                                    if (Double.parseDouble(finalValue1) >= Double.parseDouble(s)) {
                                                        finalValue1 = s;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 按照 先循环 设备资源id 找出最大值
                                    List<String> valueList2 = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        valueList2.add(currentValue);
                                    }
                                    if (valueList2.size() == 0) {
                                        finalValue2 = "";
                                    } else {
                                        for (String s : valueList2) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue2)) {
                                                    finalValue2 = s;
                                                } else {
                                                    if (Double.parseDouble(finalValue2) >= Double.parseDouble(s)) {
                                                        finalValue2 = s;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 比较 finalValue1 和 finalValue2 取最大
                                    Double finalValue_1 = 0.0;
                                    Double finalValue_2 = 0.0;
                                    Double finalValue = 0.0;
                                    if (CommonUtils.isNumeric(finalValue1)) {
                                        finalValue_1 = Double.parseDouble(finalValue1);
                                    } else {
                                        finalValue_1 = 0.0;
                                    }
                                    if (CommonUtils.isNumeric(finalValue2)) {
                                        finalValue_2 = Double.parseDouble(finalValue2);
                                    } else {
                                        finalValue_2 = 0.0;
                                    }
                                    if (finalValue_1 <= finalValue_2) {
                                        finalValue = finalValue_1;
                                    } else {
                                        finalValue = finalValue_2;
                                    }

                                    BaseCapacityRule l = new BaseCapacityRule();
                                    l.setBaseCapacityRuleName(lineBaseParamName);
                                    l.setLineBaseParamKey(lineBaseParamKey);
                                    l.setLineBaseParamValue("0.0".equals(finalValue.toString()) ? "" : CommonUtils.removeZeros(finalValue.toString()));
                                    l.setLineBaseBigTypeId(bigTypeId);
                                    l.setLineBaseSmallTypeId(smallTypeId);
                                    l.setValueFromOnline(valueFromOnline);
                                    finalKeyAndValueList.add(l);
                                    //System.out.println(lineBaseParam.getLineBaseParamName() + "：" + lineBaseParamKey + "：" + finalValue);
                                } else if ("3".equals(baseCapacityRuleType.toString())) {
                                    //取当前值
                                    if (valueFromOnline == 3) {
                                        if (pcbaLine.getPcbaProcessId().equals(aoiPressfitProcessId)) {
                                            // aoi-pressfit
                                            List<String> valueList = new ArrayList<>();
                                            if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                                for (String s : keyArr) {
                                                    System.out.println("key======：" + s);
                                                    // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                                    String currentValue = "";
                                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                                        PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                        if (pcbaDeviceRelatedDeviceParam != null) {
                                                            currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                            break;
                                                        }

                                                    }
                                                    valueList.add(currentValue);
                                                }
                                            }
                                            String finalValue = "";
                                            if (valueList.size() == 0) {
                                                finalValue = "";
                                            } else {
                                                finalValue = valueList.get(0);
                                            }
                                            BaseCapacityRule l = new BaseCapacityRule();
                                            l.setBaseCapacityRuleName(lineBaseParamName);
                                            l.setLineBaseParamKey(lineBaseParamKey);
                                            l.setLineBaseParamValue(finalValue);
                                            l.setLineBaseBigTypeId(bigTypeId);
                                            l.setLineBaseSmallTypeId(smallTypeId);
                                            l.setValueFromOnline(valueFromOnline);
                                            finalKeyAndValueList.add(l);
                                        } else if (pcbaLine.getPcbaProcessId().equals(pressfitProcessId)) {
                                            // pressfit
                                            List<String> valueList = new ArrayList<>();
                                            if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                                for (String s : keyArr) {
                                                    //System.out.println("key：" + s);
                                                    // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                                    String currentValue = "";
                                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                                        String deviceUse = deviceResourceId.get("deviceUse");
                                                        if (DeviceUseName.AOI_PRESSFIT.equals(deviceUse)) {
                                                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                            if (pcbaDeviceRelatedDeviceParam != null) {
                                                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                                break;
                                                            }
                                                        }
                                                    }
                                                    valueList.add(currentValue);
                                                }
                                            }
                                            String finalValue = "";
                                            if (valueList.size() == 0) {
                                                finalValue = "";
                                            } else {
                                                finalValue = valueList.get(0);
                                            }
                                            BaseCapacityRule l = new BaseCapacityRule();
                                            l.setBaseCapacityRuleName(lineBaseParamName);
                                            l.setLineBaseParamKey(lineBaseParamKey);
                                            l.setLineBaseParamValue(finalValue);
                                            l.setLineBaseBigTypeId(bigTypeId);
                                            l.setLineBaseSmallTypeId(smallTypeId);
                                            l.setValueFromOnline(valueFromOnline);
                                            finalKeyAndValueList.add(l);
                                        } else {
                                            BaseCapacityRule l = new BaseCapacityRule();
                                            l.setBaseCapacityRuleName(lineBaseParamName);
                                            l.setLineBaseParamKey(lineBaseParamKey);
                                            l.setLineBaseParamValue("NA");
                                            l.setLineBaseBigTypeId(bigTypeId);
                                            l.setLineBaseSmallTypeId(smallTypeId);
                                            l.setValueFromOnline(valueFromOnline);
                                            finalKeyAndValueList.add(l);
                                        }
                                    } else {
                                        if (DeviceUseName.AOI_LUHOU.equals(pcbaDeviceUse)) {
                                            List<String> valueList = new ArrayList<>();
                                            if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                                String currentValue = "";
                                                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                                    String deviceUse = deviceResourceId.get("deviceUse");
                                                    if (DeviceUseName.AOI_LUHOU.equals(deviceUse)) {
                                                        String[] lineBaseParamKeys = new String[]{"input_1690168363211", "input_1690168363212", "input_1690168363213", "input_1690168363214"};
                                                        for (String key : lineBaseParamKeys) {
                                                            if (key.equals(lineBaseParamKey)) {
                                                                BaseCapacityRule baseCapacityRuleByKey = baseCapacityRuleDao.getBaseCapacityRuleByKey(key);
                                                                if (baseCapacityRuleByKey != null) {
                                                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(baseCapacityRuleByKey.getPcbaDeviceParamKeys(), Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                                    if (pcbaDeviceRelatedDeviceParam != null) {
                                                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                                    }
                                                                    valueList.add(currentValue);
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            String finalValue = "";
                                            if (valueList.size() == 0) {
                                                finalValue = "";
                                            } else {
                                                finalValue = valueList.get(0);
                                            }
                                            BaseCapacityRule l = new BaseCapacityRule();
                                            l.setBaseCapacityRuleName(lineBaseParamName);
                                            l.setLineBaseParamKey(lineBaseParamKey);
                                            l.setLineBaseParamValue(finalValue);
                                            l.setLineBaseBigTypeId(bigTypeId);
                                            l.setLineBaseSmallTypeId(smallTypeId);
                                            l.setValueFromOnline(valueFromOnline);
                                            finalKeyAndValueList.add(l);
                                        } else {
                                            List<String> valueList = new ArrayList<>();
                                            if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                                for (String s : keyArr) {
                                                    //System.out.println("key：" + s);
                                                    // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                                    String currentValue = "";
                                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                                        PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                        if (pcbaDeviceRelatedDeviceParam != null) {
                                                            currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                            break;
                                                        }

                                                    }
                                                    valueList.add(currentValue);
                                                }
                                            }
                                            String finalValue = "";
                                            if (valueList.size() == 0) {
                                                finalValue = "";
                                            } else {
                                                finalValue = valueList.get(0);
                                            }
                                            BaseCapacityRule l = new BaseCapacityRule();
                                            l.setBaseCapacityRuleName(lineBaseParamName);
                                            l.setLineBaseParamKey(lineBaseParamKey);
                                            l.setLineBaseParamValue(finalValue);
                                            l.setLineBaseBigTypeId(bigTypeId);
                                            l.setLineBaseSmallTypeId(smallTypeId);
                                            l.setValueFromOnline(valueFromOnline);
                                            finalKeyAndValueList.add(l);
                                        }
                                    }
                                } else if ("4".equals(baseCapacityRuleType.toString())) {
                                    //取当前线体中所有该设备资源当前值 前两位判定大小 【同时取最小值】
                                    String finalValue1 = "";
                                    String finalValue2 = "";

                                    // 按照 先循环 key 找出最大值
                                    List<String> valueList = new ArrayList<>();
                                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                                        for (String s : keyArr) {
                                            System.out.println("key：" + s);
                                            // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                            String currentValue = "";
                                            for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                            valueList.add(currentValue);
                                        }
                                    }
                                    if (valueList.size() == 0) {
                                        finalValue1 = "";
                                    } else {
                                        for (String s : valueList) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue1)) {
                                                    finalValue1 = s;
                                                } else {
                                                    String ss = "";
                                                    if (s.length() >= 2) {
                                                        ss = s.substring(0, 2);
                                                        if (Double.parseDouble(ss) <= Double.parseDouble(finalValue1.substring(0, 2))) {
                                                            finalValue1 = s;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 按照 先循环 设备资源id 找出最大值
                                    List<String> valueList2 = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        valueList2.add(currentValue);
                                    }
                                    if (valueList2.size() == 0) {
                                        finalValue2 = "";
                                    } else {
                                        for (String s : valueList2) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue2)) {
                                                    finalValue2 = s;
                                                } else {
                                                    String ss = "";
                                                    if (s.length() >= 2) {
                                                        ss = s.substring(0, 2);
                                                        if (Double.parseDouble(ss) <= Double.parseDouble(finalValue2.substring(0, 2))) {
                                                            finalValue2 = s;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 比较 finalValue1 和 finalValue2 前2位 取最小
                                    String finalValue_1 = "";
                                    String finalValue_2 = "";
                                    String finalValue = "";
                                    if (finalValue1.length() >= 2 && CommonUtils.isNumeric(finalValue1.substring(0, 2))) {
                                        finalValue_1 = finalValue1;
                                    } else {
                                        finalValue_1 = "";
                                    }
                                    if (finalValue2.length() >= 2 && CommonUtils.isNumeric(finalValue2.substring(0, 2))) {
                                        finalValue_2 = finalValue2;
                                    } else {
                                        finalValue_2 = "";
                                    }
                                    if (!"".equals(finalValue_1) && !"".equals(finalValue_2)) {
                                        if (Double.parseDouble(finalValue1.substring(0, 2)) <= Double.parseDouble(finalValue2.substring(0, 2))) {
                                            finalValue = finalValue_1;
                                        } else {
                                            finalValue = finalValue_2;
                                        }
                                    } else {
                                        if ("".equals(finalValue_1)) {
                                            finalValue = finalValue_2;
                                        } else {
                                            finalValue = finalValue_1;
                                        }
                                    }

                                    BaseCapacityRule l = new BaseCapacityRule();
                                    l.setBaseCapacityRuleName(lineBaseParamName);
                                    l.setLineBaseParamKey(lineBaseParamKey);
                                    l.setLineBaseParamValue(finalValue);
                                    l.setLineBaseBigTypeId(bigTypeId);
                                    l.setLineBaseSmallTypeId(smallTypeId);
                                    l.setValueFromOnline(valueFromOnline);
                                    finalKeyAndValueList.add(l);
                                } else if ("5".equals(baseCapacityRuleType.toString())) {
                                    //取当前线体中所有该设备资源当前值 前两位判定大小 【同时取最大值】
                                    String finalValue1 = "";
                                    String finalValue2 = "";

                                    // 按照 先循环 key 找出最大值
                                    List<String> valueList = new ArrayList<>();
                                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                                        for (String s : keyArr) {
                                            //System.out.println("key：" + s);
                                            // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                            String currentValue = "";
                                            for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                            valueList.add(currentValue);
                                        }
                                    }
                                    if (valueList.size() == 0) {
                                        finalValue1 = "";
                                    } else {
                                        for (String s : valueList) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue1)) {
                                                    finalValue1 = s;
                                                } else {
                                                    String ss = "";
                                                    if (s.length() >= 2) {
                                                        ss = s.substring(0, 2);
                                                        if (Double.parseDouble(ss) >= Double.parseDouble(finalValue1.substring(0, 2))) {
                                                            finalValue1 = s;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 按照 先循环 设备资源id 找出最大值
                                    List<String> valueList2 = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        valueList2.add(currentValue);
                                    }
                                    if (valueList2.size() == 0) {
                                        finalValue2 = "";
                                    } else {
                                        for (String s : valueList2) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue2)) {
                                                    finalValue2 = s;
                                                } else {
                                                    String ss = "";
                                                    if (s.length() >= 2) {
                                                        ss = s.substring(0, 2);
                                                        if (Double.parseDouble(ss) >= Double.parseDouble(finalValue2.substring(0, 2))) {
                                                            finalValue2 = s;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 比较 finalValue1 和 finalValue2 前2位 取最大
                                    String finalValue_1 = "";
                                    String finalValue_2 = "";
                                    String finalValue = "";
                                    if (finalValue1.length() >= 2 && CommonUtils.isNumeric(finalValue1.substring(0, 2))) {
                                        finalValue_1 = finalValue1;
                                    } else {
                                        finalValue_1 = "";
                                    }
                                    if (finalValue2.length() >= 2 && CommonUtils.isNumeric(finalValue2.substring(0, 2))) {
                                        finalValue_2 = finalValue2;
                                    } else {
                                        finalValue_2 = "";
                                    }
                                    if (!"".equals(finalValue_1) && !"".equals(finalValue_2)) {
                                        if (Double.parseDouble(finalValue1.substring(0, 2)) >= Double.parseDouble(finalValue2.substring(0, 2))) {
                                            finalValue = finalValue_1;
                                        } else {
                                            finalValue = finalValue_2;
                                        }
                                    } else {
                                        if ("".equals(finalValue_1)) {
                                            finalValue = finalValue_2;
                                        } else {
                                            finalValue = finalValue_1;
                                        }
                                    }

                                    BaseCapacityRule l = new BaseCapacityRule();
                                    l.setBaseCapacityRuleName(lineBaseParamName);
                                    l.setLineBaseParamKey(lineBaseParamKey);
                                    l.setLineBaseParamValue(finalValue);
                                    l.setLineBaseBigTypeId(bigTypeId);
                                    l.setLineBaseSmallTypeId(smallTypeId);
                                    l.setValueFromOnline(valueFromOnline);
                                    finalKeyAndValueList.add(l);
                                } else if ("6".equals(baseCapacityRuleType.toString())) {
                                    // 按照设备资源循环 求 值的和
                                    // 取和值
                                    List<String> valueList = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        valueList.add(currentValue);
                                    }
                                    String finalValue = "";
                                    Double finalValueDouble = 0.0;
                                    if (valueList.size() == 0) {
                                        finalValue = "";
                                    } else {
                                        for (String s : valueList) {
                                            // 取和
                                            if (CommonUtils.isNumeric(s)) {
                                                finalValueDouble = finalValueDouble + Double.parseDouble(s);
                                            }
                                        }
                                        if (finalValueDouble > 0) {
                                            finalValue = CommonUtils.removeZeros(finalValueDouble.toString());
                                        }
                                    }
                                    BaseCapacityRule l = new BaseCapacityRule();
                                    l.setBaseCapacityRuleName(lineBaseParamName);
                                    l.setLineBaseParamKey(lineBaseParamKey);
                                    l.setLineBaseParamValue(finalValue);
                                    l.setLineBaseBigTypeId(bigTypeId);
                                    l.setLineBaseSmallTypeId(smallTypeId);
                                    l.setValueFromOnline(valueFromOnline);
                                    finalKeyAndValueList.add(l);
                                } else if ("7".equals(baseCapacityRuleType.toString())) {
                                    // 只要有一台为”是“，则为是；全部”否“，则为”否“
                                    List<String> valueList1 = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        if (!"".equals(currentValue)) {
                                            valueList1.add(currentValue);
                                        }
                                    }

                                    List<String> valueList2 = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        if (!"".equals(currentValue)) {
                                            valueList2.add(currentValue);
                                        }
                                    }

                                    String finalValue = "";
                                    if (valueList1.size() > 0 || valueList2.size() > 0) {
                                        if (valueList1.contains("是") || valueList2.contains("是")) {
                                            finalValue = "是";
                                        } else {
                                            finalValue = "否";
                                        }
                                    }

                                    BaseCapacityRule l = new BaseCapacityRule();
                                    l.setBaseCapacityRuleName(lineBaseParamName);
                                    l.setLineBaseParamKey(lineBaseParamKey);
                                    l.setLineBaseParamValue(finalValue);
                                    l.setLineBaseBigTypeId(bigTypeId);
                                    l.setLineBaseSmallTypeId(smallTypeId);
                                    l.setValueFromOnline(valueFromOnline);
                                    finalKeyAndValueList.add(l);
                                } else if ("8".equals(baseCapacityRuleType.toString())) {
                                    // 只要任意一台填写”有“，则为”有“
                                    List<String> valueList1 = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        if (!"".equals(currentValue)) {
                                            valueList1.add(currentValue);
                                        }
                                    }

                                    List<String> valueList2 = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        if (!"".equals(currentValue)) {
                                            valueList2.add(currentValue);
                                        }
                                    }

                                    String finalValue = "";
                                    if (valueList1.size() > 0 || valueList2.size() > 0) {
                                        if (valueList1.contains("有") || valueList2.contains("有")) {
                                            finalValue = "有";
                                        } else {
                                            finalValue = "";
                                        }
                                    }

                                    BaseCapacityRule l = new BaseCapacityRule();
                                    l.setBaseCapacityRuleName(lineBaseParamName);
                                    l.setLineBaseParamKey(lineBaseParamKey);
                                    l.setLineBaseParamValue(finalValue);
                                    l.setLineBaseBigTypeId(bigTypeId);
                                    l.setLineBaseSmallTypeId(smallTypeId);
                                    l.setValueFromOnline(valueFromOnline);
                                    finalKeyAndValueList.add(l);
                                } else if ("9".equals(baseCapacityRuleType.toString())) {
                                    // 9：取第一个集合的最大值在和第二个集合取最小值
                                    // 第一个集合取最大值 pcbaDeviceParamKeys2
                                    String finalValue1_ = "";
                                    String finalValue2_ = "";

                                    // 按照 先循环 key 找出最大值
                                    List<String> valueList_ = new ArrayList<>();
                                    if (pcbaDeviceParamKeys2 != null && !"".equals(pcbaDeviceParamKeys2)) {
                                        String[] keyArr = pcbaDeviceParamKeys2.split(",");
                                        for (String s : keyArr) {
                                            //System.out.println("key：" + s);
                                            // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                            String currentValue = "";
                                            for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                            valueList_.add(currentValue);
                                        }
                                    }
                                    if (valueList_.size() == 0) {
                                        finalValue1_ = "";
                                    } else {
                                        for (String s : valueList_) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue1_)) {
                                                    finalValue1_ = s;
                                                } else {
                                                    if (Double.parseDouble(finalValue1_) <= Double.parseDouble(s)) {
                                                        finalValue1_ = s;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 按照 先循环 设备资源id 找出最大值
                                    List<String> valueList2_ = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys2 != null && !"".equals(pcbaDeviceParamKeys2)) {
                                            String[] keyArr = pcbaDeviceParamKeys2.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        valueList2_.add(currentValue);
                                    }
                                    if (valueList2_.size() == 0) {
                                        finalValue2_ = "";
                                    } else {
                                        for (String s : valueList2_) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue2_)) {
                                                    finalValue2_ = s;
                                                } else {
                                                    if (Double.parseDouble(finalValue2_) <= Double.parseDouble(s)) {
                                                        finalValue2_ = s;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 比较 finalValue1 和 finalValue2 取最大
                                    Double finalValue_1_ = 0.0;
                                    Double finalValue_2_ = 0.0;
                                    Double finalValue_ = 0.0;
                                    if (CommonUtils.isNumeric(finalValue1_)) {
                                        finalValue_1_ = Double.parseDouble(finalValue1_);
                                    } else {
                                        finalValue_1_ = 0.0;
                                    }
                                    if (CommonUtils.isNumeric(finalValue2_)) {
                                        finalValue_2_ = Double.parseDouble(finalValue2_);
                                    } else {
                                        finalValue_2_ = 0.0;
                                    }
                                    if (finalValue_1_ >= finalValue_2_) {
                                        finalValue_ = finalValue_1_;
                                    } else {
                                        finalValue_ = finalValue_2_;
                                    }


                                    // 再取最小值
                                    String finalValue1 = "";
                                    String finalValue2 = "";

                                    // 按照 先循环 key 找出最大值
                                    List<String> valueList = new ArrayList<>();
                                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                                        for (String s : keyArr) {
                                            //System.out.println("key：" + s);
                                            // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                            String currentValue = "";
                                            for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                            valueList.add(currentValue);
                                        }
                                    }
                                    if (valueList.size() == 0) {
                                        finalValue1 = "";
                                    } else {
                                        for (String s : valueList) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue1)) {
                                                    finalValue1 = s;
                                                } else {
                                                    if (Double.parseDouble(finalValue1) >= Double.parseDouble(s)) {
                                                        finalValue1 = s;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 按照 先循环 设备资源id 找出最大值
                                    List<String> valueList2 = new ArrayList<>();
                                    for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                        String currentValue = "";
                                        if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                                            for (String s : keyArr) {
                                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                                if (pcbaDeviceRelatedDeviceParam != null) {
                                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                                    break;
                                                }
                                            }
                                        }
                                        valueList2.add(currentValue);
                                    }
                                    if (valueList2.size() == 0) {
                                        finalValue2 = "";
                                    } else {
                                        for (String s : valueList2) {
                                            // 取最大值
                                            // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                            if (CommonUtils.isNumeric(s)) {
                                                if ("".equals(finalValue2)) {
                                                    finalValue2 = s;
                                                } else {
                                                    if (Double.parseDouble(finalValue2) >= Double.parseDouble(s)) {
                                                        finalValue2 = s;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 比较 finalValue1 和 finalValue2 取最大
                                    Double finalValue_1 = 0.0;
                                    Double finalValue_2 = 0.0;
                                    Double finalValue = 0.0;
                                    if (CommonUtils.isNumeric(finalValue1)) {
                                        finalValue_1 = Double.parseDouble(finalValue1);
                                    } else {
                                        finalValue_1 = 0.0;
                                    }
                                    if (CommonUtils.isNumeric(finalValue2)) {
                                        finalValue_2 = Double.parseDouble(finalValue2);
                                    } else {
                                        finalValue_2 = 0.0;
                                    }
                                    if (finalValue_1 <= finalValue_2) {
                                        finalValue = finalValue_1;
                                    } else {
                                        finalValue = finalValue_2;
                                    }

                                    // 将 finalValue_ 和 finalValue 取最小值
                                    if (finalValue_ < finalValue) {
                                        finalValue = finalValue_;
                                    }

                                    BaseCapacityRule l = new BaseCapacityRule();
                                    l.setBaseCapacityRuleName(lineBaseParamName);
                                    l.setLineBaseParamKey(lineBaseParamKey);
                                    l.setLineBaseParamValue("0.0".equals(finalValue.toString()) ? "" : CommonUtils.removeZeros(finalValue.toString()));
                                    l.setLineBaseBigTypeId(bigTypeId);
                                    l.setLineBaseSmallTypeId(smallTypeId);
                                    l.setValueFromOnline(valueFromOnline);
                                    finalKeyAndValueList.add(l);
                                } else {
                                    BaseCapacityRule l = new BaseCapacityRule();
                                    l.setBaseCapacityRuleName(lineBaseParamName);
                                    l.setLineBaseParamKey(lineBaseParamKey);
                                    l.setLineBaseParamValue("");
                                    l.setLineBaseBigTypeId(bigTypeId);
                                    l.setLineBaseSmallTypeId(smallTypeId);
                                    l.setValueFromOnline(valueFromOnline);
                                    finalKeyAndValueList.add(l);
                                }
                            } else {
                                BaseCapacityRule l = new BaseCapacityRule();
                                l.setBaseCapacityRuleName(lineBaseParamName);
                                l.setLineBaseParamKey(lineBaseParamKey);
                                l.setLineBaseParamValue("");
                                l.setLineBaseBigTypeId(bigTypeId);
                                l.setLineBaseSmallTypeId(smallTypeId);
                                l.setValueFromOnline(valueFromOnline);
                                finalKeyAndValueList.add(l);
                                //System.out.println(lineBaseParam.getLineBaseParamName() + "：" + lineBaseParamKey + "：" + "");
                            }

                            // 超长线体特殊处理
                            Integer pcbaLineLevel = pcbaLine.getPcbaLineLevel();
                            LineLevel lineLevelById = lineLevelDao.getLineLevelById(pcbaLineLevel);
                            if(lineLevelById != null && lineLevelById.getLineLevelName().contains("超长")){
                                // 非自动化  input_1691733801    input_1691733802
                                // 自动化    input_1691733827   input_1691733828
                                if("input_1690168363101".equals(lineBaseParamKey)){
                                    if(lineLevelById.getLineLevelName().contains("自动化")){
                                        // input_1691733827
                                        LineTechCapacityValue input_1691733827 = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(pcbaLineId, "input_1691733827");
                                        if(input_1691733827 != null && input_1691733827.getLineTechCapacityParamValueActual() != null && !"".equals(input_1691733827.getLineTechCapacityParamValueActual())){
                                            // 修改值
                                            for (BaseCapacityRule capacityRule : finalKeyAndValueList) {
                                                if(capacityRule.getLineBaseParamKey().equals("input_1690168363101")){
                                                    capacityRule.setLineBaseParamValue(input_1691733827.getLineTechCapacityParamValueActual());
                                                }
                                            }
                                        }
                                    }else{
                                        // input_1691733801
                                        LineTechCapacityValue input_1691733801 = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(pcbaLineId, "input_1691733801");
                                        if(input_1691733801 != null && input_1691733801.getLineTechCapacityParamValueActual() != null && !"".equals(input_1691733801.getLineTechCapacityParamValueActual())){
                                            // 修改值
                                            for (BaseCapacityRule capacityRule : finalKeyAndValueList) {
                                                if(capacityRule.getLineBaseParamKey().equals("input_1690168363101")){
                                                    capacityRule.setLineBaseParamValue(input_1691733801.getLineTechCapacityParamValueActual());
                                                }
                                            }
                                        }
                                    }
                                }
                                if("input_1690168363102".equals(lineBaseParamKey)){
                                    if(lineLevelById.getLineLevelName().contains("自动化")){
                                        // input_1691733828
                                        LineTechCapacityValue input_1691733828 = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(pcbaLineId, "input_1691733828");
                                        if(input_1691733828 != null && input_1691733828.getLineTechCapacityParamValueActual() != null && !"".equals(input_1691733828.getLineTechCapacityParamValueActual())){
                                            // 修改值
                                            for (BaseCapacityRule capacityRule : finalKeyAndValueList) {
                                                if(capacityRule.getLineBaseParamKey().equals("input_1690168363102")){
                                                    capacityRule.setLineBaseParamValue(input_1691733828.getLineTechCapacityParamValueActual());
                                                }
                                            }
                                        }
                                    }else{
                                        // input_1691733802
                                        LineTechCapacityValue input_1691733802 = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(pcbaLineId, "input_1691733802");
                                        if(input_1691733802 != null && input_1691733802.getLineTechCapacityParamValueActual() != null && !"".equals(input_1691733802.getLineTechCapacityParamValueActual())){
                                            // 修改值
                                            for (BaseCapacityRule capacityRule : finalKeyAndValueList) {
                                                if(capacityRule.getLineBaseParamKey().equals("input_1690168363102")){
                                                    capacityRule.setLineBaseParamValue(input_1691733802.getLineTechCapacityParamValueActual());
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        } else {
                            BaseCapacityRule l = new BaseCapacityRule();
                            l.setBaseCapacityRuleName(lineBaseParamName);
                            l.setLineBaseParamKey(lineBaseParamKey);
                            l.setLineBaseParamValue("");
                            l.setLineBaseBigTypeId(bigTypeId);
                            l.setLineBaseSmallTypeId(smallTypeId);
                            l.setValueFromOnline(valueFromOnline);
                            finalKeyAndValueList.add(l);
                        }
                        /*}else{
                            LineBaseParam l = new LineBaseParam();
                            l.setLineBaseParamName(lineBaseParamName);
                            l.setLineBaseParamKey(lineBaseParamKey);
                            l.setLineBaseParamValue("");
                            l.setLineBaseBigTypeId(bigTypeId);
                            l.setLineBaseSmallTypeId(smallTypeId);
                            finalKeyAndValueList.add(l);
                        }*/
                    }
                }

                // 按照分类重新构造数据
                Integer pcbaProcessId = pcbaLine.getPcbaProcessId();
                // 根据 pcbaProcessId 得到 符合条件的 lineBaseSmallType 反推 lineBaseBigType
                List<LineBaseSmallType> lineBaseSmallTypeList = lineBaseSmallTypeDao.getAllLineBaseSmallTypeByBigType("", null);
                List<LineBaseSmallType> newLineBaseSmallTypeList = new ArrayList<>();
                for (LineBaseSmallType lineBaseSmallType : lineBaseSmallTypeList) {
                    if (lineBaseSmallType.getPcbaProcessId().equals(pcbaProcessId)) {
                        newLineBaseSmallTypeList.add(lineBaseSmallType);
                    }
                }
                List<Integer> bigTypes = new ArrayList<>();
                for (LineBaseSmallType lineBaseSmallType : newLineBaseSmallTypeList) {
                    Integer lineBaseBigTypeId = lineBaseSmallType.getLineBaseBigTypeId();
                    bigTypes.add(lineBaseBigTypeId);
                }
                //去重
                Set<Integer> set = new HashSet<>(bigTypes);
                List<Integer> bigTypesNew = new ArrayList<>(set);
                List<LineBaseBigType> lineBaseBigTypeList = new ArrayList<>();
                for (Integer bigTypeId : bigTypesNew) {
                    LineBaseBigType lineBaseBigType = lineBaseBigTypeDao.getLineBaseBigTypeById(bigTypeId);
                    if (lineBaseBigType != null) {
                        List<LineBaseSmallType> lineBaseSmallTypeListNew = new ArrayList<>();
                        for (LineBaseSmallType lineBaseSmallType : newLineBaseSmallTypeList) {
                            if (lineBaseSmallType.getLineBaseBigTypeId().equals(bigTypeId)) {
                                lineBaseSmallTypeListNew.add(lineBaseSmallType);
                            }
                        }
                        for (LineBaseSmallType lineBaseSmallType : lineBaseSmallTypeListNew) {
                            Integer lineBaseSmallTypeId = lineBaseSmallType.getLineBaseSmallTypeId();
                            List<BaseCapacityRule> baseCapacityRuleList1 = new ArrayList<>();
                            for (BaseCapacityRule baseCapacityRule1 : finalKeyAndValueList) {
                                if (baseCapacityRule1.getLineBaseBigTypeId().equals(bigTypeId) &&
                                        baseCapacityRule1.getLineBaseSmallTypeId().toString().equals(lineBaseSmallTypeId.toString())
                                ) {
                                    baseCapacityRuleList1.add(baseCapacityRule1);
                                }
                            }
                            lineBaseSmallType.setBaseCapacityRuleList(baseCapacityRuleList1);
                        }
                        lineBaseBigType.setLineBaseSmallTypeList(lineBaseSmallTypeListNew);
                        lineBaseBigTypeList.add(lineBaseBigType);
                    }
                }

                //删除并新增记录基线能力
                lineBaseCapacityValueDao.deleteLineBaseCapacityValueByLineId(pcbaLineId);
                for (LineBaseBigType lineBaseBigType : lineBaseBigTypeList) {
                    for (LineBaseSmallType lineBaseSmallType : lineBaseBigType.getLineBaseSmallTypeList()) {
                        for (BaseCapacityRule baseCapacityRule : lineBaseSmallType.getBaseCapacityRuleList()) {
                            LineBaseCapacityValue addLineBaseCapacityValue = new LineBaseCapacityValue();
                            addLineBaseCapacityValue.setLineBaseCapacityParamKey(baseCapacityRule.getLineBaseParamKey());
                            addLineBaseCapacityValue.setPcbaLineId(pcbaLineId);
                            addLineBaseCapacityValue.setLineBaseCapacityParamValue(baseCapacityRule.getLineBaseParamValue());
                            addLineBaseCapacityValue.setLineBaseCapacityParamName(baseCapacityRule.getBaseCapacityRuleName());
                            addLineBaseCapacityValue.setCreateTime(new Date());
                            lineBaseCapacityValueDao.addLineBaseCapacityValue(addLineBaseCapacityValue);
                        }
                    }
                }

                Map<String, Object> map = new HashMap<>();
                map.put("finalKeyAndValueList", finalKeyAndValueList);
                map.put("lineBaseBigTypeList", lineBaseBigTypeList);
                return ResultUtil.success(map);

                // 按照分类重新构造数据
                /*List<LineBaseBigType> lineBaseBigTypeList = lineBaseBigTypeDao.getAllLineBaseBigType("");
                for (LineBaseBigType lineBaseBigType : lineBaseBigTypeList) {
                    Integer lineBaseBigTypeId = lineBaseBigType.getLineBaseBigTypeId();
                    List<LineBaseSmallType> lineBaseSmallTypeList = lineBaseSmallTypeDao.getAllLineBaseSmallTypeByBigType("", lineBaseBigTypeId);
                    List<LineBaseSmallType> newLineBaseSmallTypeList = new ArrayList<>();
                    for (LineBaseSmallType lineBaseSmallType : lineBaseSmallTypeList) {
                        if(lineBaseSmallType.getPcbaProcessId().equals(pcbaProcessId)){
                            newLineBaseSmallTypeList.add(lineBaseSmallType);
                        }
                    }
                    for (LineBaseSmallType lineBaseSmallType : newLineBaseSmallTypeList) {
                        Integer lineBaseSmallTypeId = lineBaseSmallType.getLineBaseSmallTypeId();
                        List<LineBaseParam> lineBaseParamArrayList = new ArrayList<>();
                        for (LineBaseParam lineBaseParam : finalKeyAndValueList) {
                            if(lineBaseParam.getLineBaseBigTypeId().toString().equals(lineBaseBigTypeId.toString()) &&
                                    lineBaseParam.getLineBaseSmallTypeId().toString().equals(lineBaseSmallTypeId.toString())
                            ){
                                lineBaseParamArrayList.add(lineBaseParam);
                            }
                        }
                        lineBaseSmallType.setLineBaseParamList(lineBaseParamArrayList);
                    }
                    lineBaseBigType.setLineBaseSmallTypeList(lineBaseSmallTypeList);
                }
                return ResultUtil.success(lineBaseBigTypeList);*/
            }
            return ResultUtil.error(500, "未找到此线体", "Can Not Find The Line", null);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result calcRoadmapCmParamValue1(Integer pcbaCompanyId, String roadmapParamKey) {
        try {
            if (pcbaCompanyId == null || "".equals(pcbaCompanyId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaCompanyId", "Miss Param pcbaCompanyId", null);
            }
            if (roadmapParamKey == null || "".equals(roadmapParamKey)) {
                return ResultUtil.error(500, "缺少参数roadmapParamKey", "Miss Param roadmapParamKey", null);
            }
            RoadmapParam roadmapParam = roadmapParamDao.getRoadmapParamByKey(roadmapParamKey);
            if (roadmapParam != null) {

                Integer valueAlgorithmType = roadmapParam.getValueAlgorithmType();
                // 1：线体工艺参数   2：工艺模板[区分设备还是特殊工艺]
                Integer keyFromType = roadmapParam.getKeyFromType();
                // keyFromType为1, techDeviceParamKeys 取值 tb_tech_capacity_rule
                // keyFromType为2, techDeviceParamKeys 取值 tb_tech_device_param
                String techDeviceParamKeys = roadmapParam.getTechDeviceParamKeys();

                List<PcbaLine> allPcbaLine = pcbaLineDao.getAllPcbaLine(null, pcbaCompanyId, null, null, null, null, null, null, null, null, null);

                List<PcbaDevice> pcbaDeviceList = new ArrayList<>();
                for (PcbaLine pcbaLine : allPcbaLine) {
                    List<PcbaDevice> pcbaDevices = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                    pcbaDeviceList.addAll(pcbaDevices);
                }

                String finalValue = "";
                if (keyFromType != null) {
                    if (keyFromType == 1) {
                        List<String> valueList = new ArrayList<>();
                        for (PcbaLine pcbaLine : allPcbaLine) {
                            if (techDeviceParamKeys != null && !"".equals(techDeviceParamKeys)) {
                                String[] keyArr = techDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    LineTechCapacityValue lineTechCapacityValueByKeyAndLineId = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(pcbaLine.getPcbaLineId(), s);
                                    if (lineTechCapacityValueByKeyAndLineId != null) {
                                        valueList.add(lineTechCapacityValueByKeyAndLineId.getLineTechCapacityParamValueActual());
                                    }
                                }

                            }
                        }
                        if (valueAlgorithmType == 1) {
                            //取最大值
                            for (String s : valueList) {
                                if (CommonUtils.isNumeric(s)) {
                                    if ("".equals(finalValue)) {
                                        finalValue = s;
                                    } else {
                                        if (Double.parseDouble(finalValue) <= Double.parseDouble(s)) {
                                            finalValue = s;
                                        }
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 2) {
                            //取最小值
                            for (String s : valueList) {
                                if (CommonUtils.isNumeric(s)) {
                                    if ("".equals(finalValue)) {
                                        finalValue = s;
                                    } else {
                                        if (Double.parseDouble(finalValue) >= Double.parseDouble(s)) {
                                            finalValue = s;
                                        }
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 3) {
                            //若有一个值为“是”，则为“是”
                            for (String s : valueList) {
                                if ("是".equals(s)) {
                                    finalValue = "是";
                                    break;
                                }
                            }
                            if ("".equals(finalValue)) {
                                finalValue = "否";
                            }
                        } else if (valueAlgorithmType == 4) {
                            //若有一个值为“支持”，则为“支持”
                            for (String s : valueList) {
                                if ("支持".equals(s)) {
                                    finalValue = "支持";
                                    break;
                                }
                            }
                            if ("".equals(finalValue)) {
                                finalValue = "不支持";
                            }
                        } else if (valueAlgorithmType == 5) {
                            //取最小值，前两位判断，如：（01005<0201<0402<0603）
                            for (String s : valueList) {
                                if (s != null) {
                                    if (s.length() >= 2) {
                                        String s2 = s.substring(0, 2);
                                        if (CommonUtils.isNumeric(s2)) {
                                            if ("".equals(finalValue)) {
                                                finalValue = s;
                                            } else {
                                                if (Double.parseDouble(finalValue.substring(0, 2)) >= Double.parseDouble(s2)) {
                                                    finalValue = s;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        } else if (valueAlgorithmType == 6) {
                            //取最大值，前两位判断，如：（0603>0402>0201>01005）
                            for (String s : valueList) {
                                if (s != null) {
                                    if (s.length() >= 2) {
                                        String s2 = s.substring(0, 2);
                                        if (CommonUtils.isNumeric(s2)) {
                                            if ("".equals(finalValue)) {
                                                finalValue = s;
                                            } else {
                                                if (Double.parseDouble(finalValue.substring(0, 2)) <= Double.parseDouble(s2)) {
                                                    finalValue = s;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 7) {
                            //所有值组合
                            // 先去重
                            List<String> myList = valueList.stream().distinct().collect(Collectors.toList());
                            for (String s : myList) {
                                finalValue = finalValue + s + ",";
                            }
                            if (!"".equals(finalValue)) {
                                finalValue = finalValue.substring(0, finalValue.length() - 1);
                            }
                        } else if (valueAlgorithmType == 8) {
                            //绝对值最小值
                            for (String s : valueList) {
                                if (CommonUtils.isNumeric(s)) {
                                    if ("".equals(finalValue)) {
                                        finalValue = s;
                                    } else {
                                        if (Math.abs(Double.parseDouble(finalValue)) >= Math.abs(Double.parseDouble(s))) {
                                            finalValue = s;
                                        }
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 9) {
                            //取最大值(特殊)，如（手工装配<工装辅助<人机协同<机械手臂）
                            for (String s : valueList) {
                                if ("机械手臂".equals(s)) {
                                    finalValue = "机械手臂";
                                    break;
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("人机协同".equals(s)) {
                                        finalValue = "人机协同";
                                        break;
                                    }
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("工装辅助".equals(s)) {
                                        finalValue = "工装辅助";
                                        break;
                                    }
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("手工装配".equals(s)) {
                                        finalValue = "手工装配";
                                        break;
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 10) {
                            //取最小值(特殊)，如（Class 100<Class 1000<Class 10000<Class 100000<Class 300000）
                            for (String s : valueList) {
                                if ("Class 100".equals(s)) {
                                    finalValue = "Class 100";
                                    break;
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("Class 1000".equals(s)) {
                                        finalValue = "Class 1000";
                                        break;
                                    }
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("Class 10000".equals(s)) {
                                        finalValue = "Class 10000";
                                        break;
                                    }
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("Class 300000".equals(s)) {
                                        finalValue = "Class 300000";
                                        break;
                                    }
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("Class 100000".equals(s)) {
                                        finalValue = "Class 100000";
                                        break;
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 11) {
                            //若有一个值为“满足”，则为“满足”
                            for (String s : valueList) {
                                if ("满足".equals(s)) {
                                    finalValue = "满足";
                                    break;
                                }
                            }
                            if ("".equals(finalValue)) {
                                finalValue = "不满足";
                            }
                        } else if (valueAlgorithmType == 12) {
                            //若有一个值为“所有器件”，则为“所有器件”
                            for (String s : valueList) {
                                if ("所有器件".equals(s)) {
                                    finalValue = "所有器件";
                                    break;
                                }
                            }
                        }
                    } else {
                        List<String> valueList = new ArrayList<>();
                        for (PcbaDevice p : pcbaDeviceList) {
                            if (techDeviceParamKeys != null && !"".equals(techDeviceParamKeys)) {
                                String[] keyArr = techDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    PcbaDeviceRelatedTechParamActual pcbaDeviceRelatedTechParamActualByPcbaDeviceIdAndKey = pcbaDeviceRelatedTechParamActualDao.getPcbaDeviceRelatedTechParamActualByPcbaDeviceIdAndKey(p.getPcbaDeviceId(), s);
                                    if (pcbaDeviceRelatedTechParamActualByPcbaDeviceIdAndKey != null) {
                                        valueList.add(pcbaDeviceRelatedTechParamActualByPcbaDeviceIdAndKey.getTechDeviceParamValue());
                                    } else {
                                        // 查特殊工艺看有没有
                                        PcbaSpecialRelatedTechParamActual pcbaSpecialRelatedTechParamActualByPcbaDeviceIdAndKey = pcbaSpecialRelatedTechParamActualDao.getPcbaSpecialRelatedTechParamActualByPcbaDeviceIdAndKey(p.getPcbaDeviceResourceId(), s, pcbaCompanyId);
                                        if (pcbaSpecialRelatedTechParamActualByPcbaDeviceIdAndKey != null) {
                                            valueList.add(pcbaSpecialRelatedTechParamActualByPcbaDeviceIdAndKey.getTechDeviceParamValue());
                                        }
                                    }
                                }

                            }
                        }
                        if (valueAlgorithmType == 1) {
                            //取最大值
                            for (String s : valueList) {
                                if (CommonUtils.isNumeric(s)) {
                                    if ("".equals(finalValue)) {
                                        finalValue = s;
                                    } else {
                                        if (Double.parseDouble(finalValue) <= Double.parseDouble(s)) {
                                            finalValue = s;
                                        }
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 2) {
                            //取最小值
                            for (String s : valueList) {
                                if (CommonUtils.isNumeric(s)) {
                                    if ("".equals(finalValue)) {
                                        finalValue = s;
                                    } else {
                                        if (Double.parseDouble(finalValue) >= Double.parseDouble(s)) {
                                            finalValue = s;
                                        }
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 3) {
                            //若有一个值为“是”，则为“是”
                            for (String s : valueList) {
                                if ("是".equals(s)) {
                                    finalValue = "是";
                                    break;
                                }
                            }
                            if ("".equals(finalValue)) {
                                finalValue = "否";
                            }
                        } else if (valueAlgorithmType == 4) {
                            //若有一个值为“支持”，则为“支持”
                            for (String s : valueList) {
                                if ("支持".equals(s)) {
                                    finalValue = "支持";
                                    break;
                                }
                            }
                            if ("".equals(finalValue)) {
                                finalValue = "不支持";
                            }
                        } else if (valueAlgorithmType == 5) {
                            //取最小值，前两位判断，如：（01005<0201<0402<0603）
                            for (String s : valueList) {
                                if (s != null) {
                                    if (s.length() >= 2) {
                                        String s2 = s.substring(0, 2);
                                        if (CommonUtils.isNumeric(s2)) {
                                            if ("".equals(finalValue)) {
                                                finalValue = s;
                                            } else {
                                                if (Double.parseDouble(finalValue.substring(0, 2)) >= Double.parseDouble(s2)) {
                                                    finalValue = s;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        } else if (valueAlgorithmType == 6) {
                            //取最大值，前两位判断，如：（0603>0402>0201>01005）
                            for (String s : valueList) {
                                if (s != null) {
                                    if (s.length() >= 2) {
                                        String s2 = s.substring(0, 2);
                                        if (CommonUtils.isNumeric(s2)) {
                                            if ("".equals(finalValue)) {
                                                finalValue = s;
                                            } else {
                                                if (Double.parseDouble(finalValue.substring(0, 2)) <= Double.parseDouble(s2)) {
                                                    finalValue = s;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 7) {
                            //所有值组合
                            // 先去重
                            List<String> myList = valueList.stream().distinct().collect(Collectors.toList());
                            for (String s : myList) {
                                finalValue = finalValue + s + ",";
                            }
                            if (!"".equals(finalValue)) {
                                finalValue = finalValue.substring(0, finalValue.length() - 1);
                            }
                        } else if (valueAlgorithmType == 8) {
                            //绝对值最小值
                            for (String s : valueList) {
                                if (CommonUtils.isNumeric(s)) {
                                    if ("".equals(finalValue)) {
                                        finalValue = s;
                                    } else {
                                        if (Math.abs(Double.parseDouble(finalValue)) >= Math.abs(Double.parseDouble(s))) {
                                            finalValue = s;
                                        }
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 9) {
                            //取最大值(特殊)，如（手工装配<工装辅助<人机协同<机械手臂）
                            for (String s : valueList) {
                                if ("机械手臂".equals(s)) {
                                    finalValue = "机械手臂";
                                    break;
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("人机协同".equals(s)) {
                                        finalValue = "人机协同";
                                        break;
                                    }
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("工装辅助".equals(s)) {
                                        finalValue = "工装辅助";
                                        break;
                                    }
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("手工装配".equals(s)) {
                                        finalValue = "手工装配";
                                        break;
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 10) {
                            //取最小值(特殊)，如（Class 100<Class 1000<Class 10000<Class 100000<Class 300000）
                            for (String s : valueList) {
                                if ("Class 100".equals(s)) {
                                    finalValue = "Class 100";
                                    break;
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("Class 1000".equals(s)) {
                                        finalValue = "Class 1000";
                                        break;
                                    }
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("Class 10000".equals(s)) {
                                        finalValue = "Class 10000";
                                        break;
                                    }
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("Class 300000".equals(s)) {
                                        finalValue = "Class 300000";
                                        break;
                                    }
                                }
                            }
                            if ("".equals(finalValue)) {
                                for (String s : valueList) {
                                    if ("Class 100000".equals(s)) {
                                        finalValue = "Class 100000";
                                        break;
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 11) {
                            //若有一个值为“满足”，则为“满足”
                            for (String s : valueList) {
                                if ("满足".equals(s)) {
                                    finalValue = "满足";
                                    break;
                                }
                            }
                            if ("".equals(finalValue)) {
                                finalValue = "不满足";
                            }
                        } else if (valueAlgorithmType == 12) {
                            //若有一个值为“所有器件”，则为“所有器件”
                            for (String s : valueList) {
                                if ("所有器件".equals(s)) {
                                    finalValue = "所有器件";
                                    break;
                                }
                            }
                        }
                    }
                }
                return ResultUtil.success(finalValue);
            } else {
                return ResultUtil.error(500, "未找到roadmapParam", "Not Found roadmapParam", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("异常了");
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    /**
     * 计算 CM 厂的 能力是否匹配
     * valueAlgorithmType: 取值算法类型
     * 1：取最大值
     * 2：取最小值
     * 3：若有一个值为“是”，则为“是”
     * 4：若有一个值为“支持”，则为“支持”
     * 5：取最小值，前两位判断，如：（01005<0201<0402<0603）
     * 6：取最大值，前两位判断，如：（0603>0402>0201>01005）
     * 7：所有值组合
     * 8：绝对值最小值
     * 9：取最大值(特殊)，如（手工装配<工装辅助<人机协同<机械手臂）
     * 10：取最小值(特殊)，如（Class 100<Class 1000<Class 10000<Class 100000<Class 300000）
     * 11：若有一个值为“满足”，则为“满足”
     * 12：若有一个值为“所有器件”，则为“所有器件”
     * <p>
     * ruleAlgorithmType:规则算法类型
     * 1：CM量产能力大于等于H3C量产能力的为“是”，否则为“否”
     * 2：等于
     * 3：空值不匹配，其余匹配
     * 4：小于等于
     */
    @Override
    public Result calcRoadmapCmIsMatchH3c(Integer valueAlgorithmType, Integer ruleAlgorithmType, String h3cValue, String cmValue) {
        try {
            if (h3cValue == null || "NA".equals(h3cValue.toUpperCase()) || "".equals(h3cValue)) {
                return ResultUtil.success("是");
            }
            if (cmValue == null || "".equals(cmValue)) {
                return ResultUtil.success("否");
            }
            String finalValue = "否";

            // 添加 valueAlgorithmType = 空的情况
            if(valueAlgorithmType != null && !"".equals(valueAlgorithmType.toString())){
                if (ruleAlgorithmType != null) {
                    if (ruleAlgorithmType == 1) {
                        // 大于等于
                        // 只能判断 valueAlgorithmType = 1，2，5，6，8，9，10
                        if (valueAlgorithmType == 1) {
                            if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                                if (Double.parseDouble(cmValue) >= Double.parseDouble(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 2) {
                            if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                                if (Double.parseDouble(cmValue) >= Double.parseDouble(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 5) {
                            if (h3cValue != null && cmValue != null && h3cValue.length() >= 2 && cmValue.length() >= 2) {
                                if (CommonUtils.isNumeric(h3cValue.substring(0, 2)) && CommonUtils.isNumeric(cmValue.substring(0, 2))) {
                                    if (Double.parseDouble(cmValue.substring(0, 2)) >= Double.parseDouble(h3cValue.substring(0, 2))) {
                                        finalValue = "是";
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 6) {
                            if (h3cValue != null && cmValue != null && h3cValue.length() >= 2 && cmValue.length() >= 2) {
                                if (CommonUtils.isNumeric(h3cValue.substring(0, 2)) && CommonUtils.isNumeric(cmValue.substring(0, 2))) {
                                    if (Double.parseDouble(cmValue.substring(0, 2)) >= Double.parseDouble(h3cValue.substring(0, 2))) {
                                        finalValue = "是";
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 8) {
                            if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                                if (Math.abs(Double.parseDouble(cmValue)) >= Math.abs(Double.parseDouble(h3cValue))) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 9) {
                            //手工装配<工装辅助<人机协同<机械手臂
                            if (h3cValue != null && cmValue != null) {
                                if (cmValue.contains("机械手臂")) {
                                    finalValue = "是";
                                } else if (cmValue.contains("人机协同")) {
                                    if (!h3cValue.contains("机械手臂")) {
                                        finalValue = "是";
                                    }
                                } else if (cmValue.contains("工装辅助")) {
                                    if (!h3cValue.contains("机械手臂") && !h3cValue.contains("人机协同")) {
                                        finalValue = "是";
                                    }
                                } else if (cmValue.contains("手工装配")) {
                                    if (!h3cValue.contains("机械手臂") && !h3cValue.contains("人机协同") && !h3cValue.contains("工装辅助")) {
                                        finalValue = "是";
                                    }
                                }
                            /*if("机械手臂".equals(cmValue)){
                                finalValue = "是";
                            }else if("人机协同".equals(cmValue)){
                                if("人机协同".equals(h3cValue) || "工装辅助".equals(h3cValue) || "手工装配".equals(h3cValue)){
                                    finalValue = "是";
                                }
                            }else if("工装辅助".equals(cmValue)){
                                if("工装辅助".equals(h3cValue) || "手工装配".equals(h3cValue)){
                                    finalValue = "是";
                                }
                            }else if("手工装配".equals(cmValue)){
                                if("手工装配".equals(h3cValue)){
                                    finalValue = "是";
                                }
                            }*/
                            }
                        } else if (valueAlgorithmType == 10) {
                            //Class 100<Class 1000<Class 10000<Class 100000<Class 300000
                            if (h3cValue != null && cmValue != null) {
                                if ("Class 300000".equals(cmValue)) {
                                    finalValue = "是";
                                } else if ("Class 100000".equals(cmValue)) {
                                    if ("Class 100000".equals(h3cValue) || "Class 10000".equals(h3cValue) || "Class 1000".equals(h3cValue) || "Class 100".equals(h3cValue)) {
                                        finalValue = "是";
                                    }
                                } else if ("Class 10000".equals(cmValue)) {
                                    if ("Class 10000".equals(h3cValue) || "Class 1000".equals(h3cValue) || "Class 100".equals(h3cValue)) {
                                        finalValue = "是";
                                    }
                                } else if ("Class 1000".equals(cmValue)) {
                                    if ("Class 1000".equals(h3cValue) || "Class 100".equals(h3cValue)) {
                                        finalValue = "是";
                                    }
                                } else if ("Class 100".equals(cmValue)) {
                                    if ("Class 100".equals(h3cValue)) {
                                        finalValue = "是";
                                    }
                                }
                            }
                        }
                    } else if (ruleAlgorithmType == 2) {
                        // 等于
                        // 只能判断 valueAlgorithmType = 1，2，5，6，8，9，10，3，4，7，11，12
                        if (valueAlgorithmType == 1) {
                            if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                                if (Double.parseDouble(cmValue) == Double.parseDouble(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 2) {
                            if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                                if (Double.parseDouble(cmValue) == Double.parseDouble(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 3) {
                            if (cmValue != null && h3cValue != null) {
                                if (cmValue.equals(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 4) {
                            if (cmValue != null && h3cValue != null) {
                                if (cmValue.equals(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 5) {
                            if (h3cValue != null && cmValue != null && h3cValue.length() >= 2 && cmValue.length() >= 2) {
                                if (CommonUtils.isNumeric(h3cValue.substring(0, 2)) && CommonUtils.isNumeric(cmValue.substring(0, 2))) {
                                    if (Double.parseDouble(cmValue.substring(0, 2)) == Double.parseDouble(h3cValue.substring(0, 2))) {
                                        finalValue = "是";
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 6) {
                            if (h3cValue != null && cmValue != null && h3cValue.length() >= 2 && cmValue.length() >= 2) {
                                if (CommonUtils.isNumeric(h3cValue.substring(0, 2)) && CommonUtils.isNumeric(cmValue.substring(0, 2))) {
                                    if (Double.parseDouble(cmValue.substring(0, 2)) == Double.parseDouble(h3cValue.substring(0, 2))) {
                                        finalValue = "是";
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 7) {
                            if (cmValue != null && h3cValue != null) {
                                String[] cmValueArr = cmValue.split(",");
                                String[] h3cValueArr = h3cValue.split(",");

                                List<Integer> flagList = new ArrayList<>();
                                if (cmValueArr.length == h3cValueArr.length) {
                                    // 长度相同的情况下再判断各个元素是否一样
                                    for (String s : cmValueArr) {
                                        int flag = 2; // 不包含
                                        if (Arrays.asList(h3cValueArr).contains(s)) {
                                            flag = 1;
                                        }
                                        flagList.add(flag);
                                    }
                                    if (!flagList.contains(2)) {
                                        finalValue = "是";
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 8) {
                            if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                                if (Math.abs(Double.parseDouble(cmValue)) == Math.abs(Double.parseDouble(h3cValue))) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 9) {
                            if (cmValue != null && h3cValue != null) {
                                if (cmValue.equals(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 10) {
                            if (cmValue != null && h3cValue != null) {
                                if (cmValue.equals(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 11) {
                            if (cmValue != null && h3cValue != null) {
                                if (cmValue.equals(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 12) {
                            if (cmValue != null && h3cValue != null) {
                                if (cmValue.equals(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        }
                    } else if (ruleAlgorithmType == 3) {
                        // 空值不匹配，其余匹配
                        // 不知道具体逻辑，暂时不写
                    } else if (ruleAlgorithmType == 4) {
                        // 小于等于
                        // 只能判断 valueAlgorithmType = 1，2，5，6，8，9，10
                        if (valueAlgorithmType == 1) {
                            if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                                if (Double.parseDouble(cmValue) <= Double.parseDouble(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 2) {
                            if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                                if (Double.parseDouble(cmValue) <= Double.parseDouble(h3cValue)) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 5) {
                            if (h3cValue != null && cmValue != null && h3cValue.length() >= 2 && cmValue.length() >= 2) {
                                if (CommonUtils.isNumeric(h3cValue.substring(0, 2)) && CommonUtils.isNumeric(cmValue.substring(0, 2))) {
                                    if (Double.parseDouble(cmValue.substring(0, 2)) <= Double.parseDouble(h3cValue.substring(0, 2))) {
                                        finalValue = "是";
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 6) {
                            if (h3cValue != null && cmValue != null && h3cValue.length() >= 2 && cmValue.length() >= 2) {
                                if (CommonUtils.isNumeric(h3cValue.substring(0, 2)) && CommonUtils.isNumeric(cmValue.substring(0, 2))) {
                                    if (Double.parseDouble(cmValue.substring(0, 2)) <= Double.parseDouble(h3cValue.substring(0, 2))) {
                                        finalValue = "是";
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 8) {
                            if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                                if (Math.abs(Double.parseDouble(cmValue)) <= Math.abs(Double.parseDouble(h3cValue))) {
                                    finalValue = "是";
                                }
                            }
                        } else if (valueAlgorithmType == 9) {
                            //手工装配<工装辅助<人机协同<机械手臂
                            if (h3cValue != null && cmValue != null) {
                            /*if("手工装配".equals(cmValue)){
                                finalValue = "是";
                            }else if("工装辅助".equals(cmValue)){
                                if("工装辅助".equals(h3cValue) || "人机协同".equals(h3cValue) || "机械手臂".equals(h3cValue)){
                                    finalValue = "是";
                                }
                            }else if("人机协同".equals(cmValue)){
                                if("人机协同".equals(h3cValue) || "机械手臂".equals(h3cValue)){
                                    finalValue = "是";
                                }
                            }else if("机械手臂".equals(cmValue)){
                                if("机械手臂".equals(h3cValue)){
                                    finalValue = "是";
                                }
                            }*/
                                if (cmValue.contains("手工装配")) {
                                    finalValue = "是";
                                } else if (cmValue.contains("工装辅助")) {
                                    if (!h3cValue.contains("手工装配")) {
                                        finalValue = "是";
                                    }
                                } else if (cmValue.contains("人机协同")) {
                                    if (!h3cValue.contains("手工装配") && !h3cValue.contains("工装辅助")) {
                                        finalValue = "是";
                                    }
                                } else if (cmValue.contains("机械手臂")) {
                                    if (!h3cValue.contains("手工装配") && !h3cValue.contains("工装辅助") && !h3cValue.contains("人机协同")) {
                                        finalValue = "是";
                                    }
                                }
                            }
                        } else if (valueAlgorithmType == 10) {
                            //Class 100<Class 1000<Class 10000<Class 100000<Class 300000
                            if (h3cValue != null && cmValue != null) {
                                if ("Class 100".equals(cmValue)) {
                                    finalValue = "是";
                                } else if ("Class 1000".equals(cmValue)) {
                                    if ("Class 1000".equals(h3cValue) || "Class 10000".equals(h3cValue) || "Class 100000".equals(h3cValue) || "Class 300000".equals(h3cValue)) {
                                        finalValue = "是";
                                    }
                                } else if ("Class 10000".equals(cmValue)) {
                                    if ("Class 10000".equals(h3cValue) || "Class 100000".equals(h3cValue) || "Class 300000".equals(h3cValue)) {
                                        finalValue = "是";
                                    }
                                } else if ("Class 100000".equals(cmValue)) {
                                    if ("Class 100000".equals(h3cValue) || "Class 300000".equals(h3cValue)) {
                                        finalValue = "是";
                                    }
                                } else if ("Class 300000".equals(cmValue)) {
                                    if ("Class 300000".equals(h3cValue)) {
                                        finalValue = "是";
                                    }
                                }
                            }
                        }
                    }
                }
            }else{
                if (ruleAlgorithmType != null) {
                    if (ruleAlgorithmType == 1) {
                        if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                            if (Double.parseDouble(cmValue) >= Double.parseDouble(h3cValue)) {
                                finalValue = "是";
                            }
                        }
                    }else if (ruleAlgorithmType == 2) {
                        if (cmValue != null && h3cValue != null) {
                            if (cmValue.equals(h3cValue)) {
                                finalValue = "是";
                            }
                        }
                    }else if (ruleAlgorithmType == 3) {

                    }else if (ruleAlgorithmType == 4) {
                        if (CommonUtils.isNumeric(h3cValue) && CommonUtils.isNumeric(cmValue)) {
                            if (Double.parseDouble(cmValue) <= Double.parseDouble(h3cValue)) {
                                finalValue = "是";
                            }
                        }
                    }
                }
            }

            return ResultUtil.success(finalValue);
        } catch (Exception e) {
            System.out.println("异常了");
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result calcIsOverSixYearInHighLine(PcbaDevice pcbaDevice, Integer lineLevel) {
        try {
            if("ergrthtyhtyh".equals(pcbaDevice.getAssetNumber())){
                System.out.println("ergrthtyhtyh");
            }
            int isOverSixYearInHighLine = 2;
//            if(pcbaDevice == null){
//                return ResultUtil.error(500, "缺少参数pcbaDevice", "Miss Param pcbaDevice", null);
//            }
            if (pcbaDevice == null) {
                return ResultUtil.success(isOverSixYearInHighLine);
            }
            Date productTime = pcbaDevice.getProductTime();
            if (productTime == null) {
                return ResultUtil.success(isOverSixYearInHighLine);
            }

            // 过滤出高端线体，目前按照线体等级中含有高端2字判定
            List<Integer> highLevelIds = new ArrayList<>();
            List<LineLevel> allLineLevel = lineLevelDao.getAllLineLevel();
            for (LineLevel ll : allLineLevel) {
                if (ll.getLineLevelName().contains("高端")) {
                    highLevelIds.add(ll.getLineLevelId());
                }
            }
            if (highLevelIds.contains(lineLevel)) {
                // 读取配置表
                List<MaintenanceConfig> maintenanceConfigByType = maintenanceConfigDao.getMaintenanceConfigByType(2);
                if (maintenanceConfigByType.size() > 0) {
                    Double forewarningAge = maintenanceConfigByType.get(0).getForewarningAge();
                    Integer forewarningAgeDisposed = maintenanceConfigByType.get(0).getForewarningAgeDisposed();
                    if (forewarningAge != null) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = productTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        if (forewarningAge < age) {
                            // 判断 是否已闭环管理逻辑
                            // 如果已闭环关闭，则判断 处理的时间 + forewarningAgeDisposed 天数 是否超过当前时间，超过继续提醒，否则不提醒了  isOverSixYearInHighLine = 3
                            Integer loopCloseStatus = pcbaDevice.getLoopCloseStatus();
                            Date loopCloseTime = pcbaDevice.getLoopCloseTime();
                            if (loopCloseStatus != null && loopCloseStatus != 1) {
                                // 未处理
                                isOverSixYearInHighLine = 1;
                            } else {
                                if (loopCloseTime != null) {
                                    LocalDate ld3 = loopCloseTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                                    double days = CommonUtils.calculateDayDifference(ld3, ld1);
                                    if(days < 0){
                                        // 正常 [一般不会出现只有修改系统时间才会出现，即把系统时间修改到上次处理时间之前]
                                        isOverSixYearInHighLine = 2;
                                    }else{
                                        if (days >= forewarningAgeDisposed) {
                                            // 处理过但是已经又超期了
                                            isOverSixYearInHighLine = 1;
                                        } else {
                                            // 处理过仍在挂起状态下
                                            isOverSixYearInHighLine = 3;
                                        }
                                    }
                                } else {
                                    // 缺少处理时间，当作没处理
                                    isOverSixYearInHighLine = 1;
                                }
                            }
                        }
                    }
                }
            }
            return ResultUtil.success(isOverSixYearInHighLine);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result calcIsAgeOverdueInLine(PcbaDevice pcbaDevice) {
        try {
            if("ergrthtyhtyh".equals(pcbaDevice.getAssetNumber())){
                System.out.println("ergrthtyhtyh");
            }
            int isAgeOverdueInLine = 2;
            if (pcbaDevice == null) {
                return ResultUtil.success(isAgeOverdueInLine);
            }
            Double deviceAge = pcbaDevice.getAge();
            if (deviceAge == null) {
                return ResultUtil.success(isAgeOverdueInLine);
            }

            List<MaintenanceConfig> maintenanceConfigList = maintenanceConfigDao.getMaintenanceConfigByType(1);
            Date d1 = new Date();
            LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            if (maintenanceConfigList.size() == 3) {
                // 获取第二条和第三条的配置值
                MaintenanceConfig m2 = maintenanceConfigList.get(1);
                MaintenanceConfig m3 = maintenanceConfigList.get(2);

                // 大于以下年限（maintenanceConfigRange2_1） 且 小于等于 以下年限（maintenanceConfigRange2_2） 发送邮件
                Double maintenanceConfigRange2_1 = m2.getMaintenanceConfigRange1();
                Double maintenanceConfigRange2_2 = m2.getMaintenanceConfigRange2();
                // 未处理预警的情况下按照 forewarningAgeUndisposed2 天数 发送
                Integer forewarningAgeUndisposed2 = m2.getForewarningAgeUndisposed();
                // 已处理预警的情况下 在 forewarningAgeDisposed2 天后，继续每隔 forewarningAgeUndisposed2 天数发送
                Integer forewarningAgeDisposed2 = m2.getForewarningAgeDisposed();

                // 大于此年限（maintenanceConfigRange3_1）发送邮件
                Double maintenanceConfigRange3_1 = m3.getMaintenanceConfigRange1();
                // 未处理预警的情况下按照 forewarningAgeUndisposed3 天数 发送
                Integer forewarningAgeUndisposed3 = m3.getForewarningAgeUndisposed();
                // 已处理预警的情况下 在 forewarningAgeDisposed3 天后，继续每隔 forewarningAgeUndisposed3 天数发送
                Integer forewarningAgeDisposed3 = m3.getForewarningAgeDisposed();

                // 1：达到预警
                // 2：未达到预警
                // 3：达到预警且已处理
                if (deviceAge > maintenanceConfigRange2_1 && deviceAge <= maintenanceConfigRange2_2) {
                    Integer ageCloseStatus = pcbaDevice.getAgeCloseStatus();
                    Integer ageCloseFlag = pcbaDevice.getAgeCloseFlag();
                    Date ageCloseTime = pcbaDevice.getAgeCloseTime();
                    if (ageCloseStatus == null || ageCloseStatus != 1) {
                        // 未处理
                        isAgeOverdueInLine = 1;
                    } else {
                        if (ageCloseTime != null) {
                            LocalDate ld3 = ageCloseTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                            double days = CommonUtils.calculateDayDifference(ld3, ld1);
                            if(days < 0) {
                                // 正常 [一般不会出现只有修改系统时间才会出现，即把系统时间修改到上次处理时间之前]
                            }else{
                                if (days >= forewarningAgeDisposed2) {
                                    // 处理已超期
                                    isAgeOverdueInLine = 1;
                                } else {
                                    // 处理过仍在挂起状态下
                                    isAgeOverdueInLine = 3;
                                }
                            }
                        } else {
                            // 缺少处理时间，当作没处理
                            isAgeOverdueInLine = 1;
                        }
                    }
                }
                if (deviceAge > maintenanceConfigRange3_1) {
                    Integer ageCloseStatus = pcbaDevice.getAgeCloseStatus();
                    Date ageCloseTime = pcbaDevice.getAgeCloseTime();
                    Integer ageCloseFlag = pcbaDevice.getAgeCloseFlag();
                    if (ageCloseStatus != null && ageCloseStatus != 1) {
                        // 未处理
                        isAgeOverdueInLine = 1;
                    } else {
                        if (ageCloseTime != null) {
                            LocalDate ld3 = ageCloseTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                            double days = CommonUtils.calculateDayDifference(ld3, ld1);
                            if(days < 0){
                                // 正常 [一般不会出现只有修改系统时间才会出现，即把系统时间修改到上次处理时间之前]
                                isAgeOverdueInLine = 2;
                            }else{
                                if (days >= forewarningAgeDisposed3) {
                                    // 处理已超期
                                    isAgeOverdueInLine = 1;
                                } else {
                                    // 处理过仍在挂起状态下
                                    // 此处增加判断 如果 ageCloseFlag = 1 ,则挂起状态立马失效
                                    if(ageCloseFlag == 2){
                                        isAgeOverdueInLine = 3;
                                    }else{
                                        isAgeOverdueInLine = 1;
                                    }
                                }
                            }
                        } else {
                            // 缺少处理时间，当作没处理
                            isAgeOverdueInLine = 1;
                        }
                    }
                }
                return ResultUtil.success(isAgeOverdueInLine);
            } else {
                return ResultUtil.success(isAgeOverdueInLine);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result refreshDeviceUpkeepStatus(Integer pcbaDeviceId) {
        try {
            int delayDay = 3;
            List<MaintenanceConfig> maintenanceConfigList = maintenanceConfigDao.getMaintenanceConfigByType(3);
            if (maintenanceConfigList.size() > 0) {
                delayDay = maintenanceConfigList.get(0).getUpkeepAdvanceOrDelay();
            }

            if (pcbaDeviceId == null || "".equals(pcbaDeviceId.toString())) {
                // 刷新所有设备
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getAllPcbaDevice(null, null, null, null, null, null, null, null, null, null);

                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    boolean isExistOverDueUpkeepFlag = false;
                    String assetNumber = pcbaDevice.getAssetNumber();
                    if (assetNumber != null && !"".equals(assetNumber)) {
                        List<Upkeep> upkeepList = upkeepDao.getUpkeepByDeviceId(pcbaDevice.getAssetNumber(), null);
                        if (upkeepList.size() > 0) {
                            // 需要对比判断保养记录
                            for (Upkeep upkeep : upkeepList) {
                                Date firstUpkeepTime = upkeep.getFirstUpkeepTime();
                                Integer upkeepType = upkeep.getUpkeepType();
                                List<String> monthBetweenDate = CommonUtils.getMonthBetweenDate(firstUpkeepTime, new Date());

                                for (int a = 0; a < monthBetweenDate.size(); a++) {
                                    List<UpkeepHistory> upkeepHistoryList = upkeepHistoryDao.getUpkeepHistoryByAssetNumberAndDueUpkeepTime(assetNumber, upkeepType, monthBetweenDate.get(a));
                                    if (upkeepHistoryList.size() > 0) {
                                        // 存在保养计划的情况下，需要更新原先的保养记录
                                        // 比如
                                        // 1.超过三天的需要改为逾期 【放入2.逻辑判断】
                                        /*for (UpkeepHistory upkeepHistory : upkeepHistoryList) {
                                            Long num = CommonUtils.getDaysBetweenTwoDate(upkeepHistory.getDueUpkeepTime(), new Date());
                                            if(upkeepHistory.getStatus() == 4){
                                                if(num > delayDay){
                                                    // 大于 delayDay 改为  逾期状态 即 5
                                                    UpkeepHistory updateUpkeepHistory = new UpkeepHistory();
                                                    updateUpkeepHistory.setUpkeepHistoryId(upkeepHistory.getUpkeepHistoryId());
                                                    updateUpkeepHistory.setUpdateTime(new Date());
                                                    updateUpkeepHistory.setStatus(5);
                                                    upkeepHistoryDao.updateUpkeepHistoryById(updateUpkeepHistory);
                                                }
                                            }
                                        }*/
                                        // 2.到达下一个节点的需要新增一个记录
                                        if (upkeepType == 1) {
                                            Calendar calendar = Calendar.getInstance();
                                            calendar.setTime(firstUpkeepTime);
                                            calendar.add(Calendar.MONTH, a);//增加1个月
                                            Date time = calendar.getTime();

                                            // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                            int status = 4;
                                            long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                            if (daysBetweenTwoDate > delayDay) {
                                                status = 5;
                                                isExistOverDueUpkeepFlag = true;
                                            }

                                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                                            //String aaaaaa = sdf.format(time);
                                            List<UpkeepHistory> upkeepHistoryByAssetNumberAndMonthAndUpkeepType = upkeepHistoryDao.getUpkeepHistoryByAssetNumberAndMonthAndUpkeepType(assetNumber, 1, sdf.format(time));
                                            if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType != null && upkeepHistoryByAssetNumberAndMonthAndUpkeepType.size() > 0) {
                                                // 存在了 判断有没有超期（状态为4超期的需要改为 5）
                                                Long num = CommonUtils.getDaysBetweenTwoDate(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getDueUpkeepTime(), new Date());
                                                if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getStatus() == 4) {
                                                    if (num > delayDay) {
                                                        // 大于 delayDay 改为  逾期状态 即 5
                                                        UpkeepHistory updateUpkeepHistory = new UpkeepHistory();
                                                        updateUpkeepHistory.setUpkeepHistoryId(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getUpkeepHistoryId());
                                                        updateUpkeepHistory.setUpdateTime(new Date());
                                                        updateUpkeepHistory.setStatus(5);
                                                        upkeepHistoryDao.updateUpkeepHistoryById(updateUpkeepHistory);
                                                    }
                                                }
                                            } else {
                                                // 不存在，新增
                                                UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                addUpkeepHistory.setAssetNumber(assetNumber);
                                                addUpkeepHistory.setCreateTime(new Date());
                                                addUpkeepHistory.setStatus(status);
                                                addUpkeepHistory.setDueUpkeepTime(time);
                                                addUpkeepHistory.setUpkeepType(upkeepType);
                                                addUpkeepHistory.setIsCurrent(1);
                                                upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                            }

                                        } else if (upkeepType == 2) {
                                            if (a % 3 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加3个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                                                List<UpkeepHistory> upkeepHistoryByAssetNumberAndMonthAndUpkeepType = upkeepHistoryDao.getUpkeepHistoryByAssetNumberAndMonthAndUpkeepType(assetNumber, 2, sdf.format(time));
                                                if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType != null && upkeepHistoryByAssetNumberAndMonthAndUpkeepType.size() > 0) {
                                                    // 存在了 判断有没有超期（状态为4超期的需要改为 5）
                                                    Long num = CommonUtils.getDaysBetweenTwoDate(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getDueUpkeepTime(), new Date());
                                                    if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getStatus() == 4) {
                                                        if (num > delayDay) {
                                                            // 大于 delayDay 改为  逾期状态 即 5
                                                            UpkeepHistory updateUpkeepHistory = new UpkeepHistory();
                                                            updateUpkeepHistory.setUpkeepHistoryId(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getUpkeepHistoryId());
                                                            updateUpkeepHistory.setUpdateTime(new Date());
                                                            updateUpkeepHistory.setStatus(5);
                                                            upkeepHistoryDao.updateUpkeepHistoryById(updateUpkeepHistory);
                                                        }
                                                    }
                                                } else {
                                                    UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                    addUpkeepHistory.setAssetNumber(assetNumber);
                                                    addUpkeepHistory.setCreateTime(new Date());
                                                    addUpkeepHistory.setStatus(status);
                                                    addUpkeepHistory.setDueUpkeepTime(time);
                                                    addUpkeepHistory.setUpkeepType(upkeepType);
                                                    addUpkeepHistory.setIsCurrent(1);
                                                    upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                                }
                                            }
                                        } else if (upkeepType == 3) {
                                            if (a % 6 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加6个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                                                List<UpkeepHistory> upkeepHistoryByAssetNumberAndMonthAndUpkeepType = upkeepHistoryDao.getUpkeepHistoryByAssetNumberAndMonthAndUpkeepType(assetNumber, 3, sdf.format(time));
                                                if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType != null && upkeepHistoryByAssetNumberAndMonthAndUpkeepType.size() > 0) {
                                                    // 存在了 判断有没有超期（状态为4超期的需要改为 5）
                                                    Long num = CommonUtils.getDaysBetweenTwoDate(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getDueUpkeepTime(), new Date());
                                                    if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getStatus() == 4) {
                                                        if (num > delayDay) {
                                                            // 大于 delayDay 改为  逾期状态 即 5
                                                            UpkeepHistory updateUpkeepHistory = new UpkeepHistory();
                                                            updateUpkeepHistory.setUpkeepHistoryId(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getUpkeepHistoryId());
                                                            updateUpkeepHistory.setUpdateTime(new Date());
                                                            updateUpkeepHistory.setStatus(5);
                                                            upkeepHistoryDao.updateUpkeepHistoryById(updateUpkeepHistory);
                                                        }
                                                    }
                                                } else {
                                                    UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                    addUpkeepHistory.setAssetNumber(assetNumber);
                                                    addUpkeepHistory.setCreateTime(new Date());
                                                    addUpkeepHistory.setStatus(status);
                                                    addUpkeepHistory.setDueUpkeepTime(time);
                                                    addUpkeepHistory.setUpkeepType(upkeepType);
                                                    addUpkeepHistory.setIsCurrent(1);
                                                    upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                                }
                                            }
                                        } else {
                                            if (a % 12 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加12个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                                                List<UpkeepHistory> upkeepHistoryByAssetNumberAndMonthAndUpkeepType = upkeepHistoryDao.getUpkeepHistoryByAssetNumberAndMonthAndUpkeepType(assetNumber, 4, sdf.format(time));
                                                if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType != null && upkeepHistoryByAssetNumberAndMonthAndUpkeepType.size() > 0) {
                                                    // 存在了 判断有没有超期（状态为4超期的需要改为 5）
                                                    Long num = CommonUtils.getDaysBetweenTwoDate(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getDueUpkeepTime(), new Date());
                                                    if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getStatus() == 4) {
                                                        if (num > delayDay) {
                                                            // 大于 delayDay 改为  逾期状态 即 5
                                                            UpkeepHistory updateUpkeepHistory = new UpkeepHistory();
                                                            updateUpkeepHistory.setUpkeepHistoryId(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getUpkeepHistoryId());
                                                            updateUpkeepHistory.setUpdateTime(new Date());
                                                            updateUpkeepHistory.setStatus(5);
                                                            upkeepHistoryDao.updateUpkeepHistoryById(updateUpkeepHistory);
                                                        }
                                                    }
                                                } else {
                                                    UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                    addUpkeepHistory.setAssetNumber(assetNumber);
                                                    addUpkeepHistory.setCreateTime(new Date());
                                                    addUpkeepHistory.setStatus(status);
                                                    addUpkeepHistory.setDueUpkeepTime(time);
                                                    addUpkeepHistory.setUpkeepType(upkeepType);
                                                    addUpkeepHistory.setIsCurrent(1);
                                                    upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                                }
                                            }
                                        }

                                    } else {
                                        // 不存在保养记录[插入表，状态需判断是否超期，超期改5，正常改4]  asset_number,create_time,status,due_upkeep_time,upkeep_type
                                        if (upkeepType == 1) {
                                            Calendar calendar = Calendar.getInstance();
                                            calendar.setTime(firstUpkeepTime);
                                            calendar.add(Calendar.MONTH, a);//增加1个月
                                            Date time = calendar.getTime();

                                            // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                            int status = 4;
                                            long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                            if (daysBetweenTwoDate > delayDay) {
                                                status = 5;
                                                isExistOverDueUpkeepFlag = true;
                                            }

                                            UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                            addUpkeepHistory.setAssetNumber(assetNumber);
                                            addUpkeepHistory.setCreateTime(new Date());
                                            addUpkeepHistory.setStatus(status);
                                            addUpkeepHistory.setDueUpkeepTime(time);
                                            addUpkeepHistory.setUpkeepType(upkeepType);
                                            addUpkeepHistory.setIsCurrent(1);
                                            upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                        } else if (upkeepType == 2) {
                                            if (a % 3 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加3个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                addUpkeepHistory.setAssetNumber(assetNumber);
                                                addUpkeepHistory.setCreateTime(new Date());
                                                addUpkeepHistory.setStatus(status);
                                                addUpkeepHistory.setDueUpkeepTime(time);
                                                addUpkeepHistory.setUpkeepType(upkeepType);
                                                addUpkeepHistory.setIsCurrent(1);
                                                upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                            }
                                        } else if (upkeepType == 3) {
                                            if (a % 6 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加6个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                addUpkeepHistory.setAssetNumber(assetNumber);
                                                addUpkeepHistory.setCreateTime(new Date());
                                                addUpkeepHistory.setStatus(status);
                                                addUpkeepHistory.setDueUpkeepTime(time);
                                                addUpkeepHistory.setUpkeepType(upkeepType);
                                                addUpkeepHistory.setIsCurrent(1);
                                                upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                            }
                                        } else {
                                            if (a % 12 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加12个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                addUpkeepHistory.setAssetNumber(assetNumber);
                                                addUpkeepHistory.setCreateTime(new Date());
                                                addUpkeepHistory.setStatus(status);
                                                addUpkeepHistory.setDueUpkeepTime(time);
                                                addUpkeepHistory.setUpkeepType(upkeepType);
                                                addUpkeepHistory.setIsCurrent(1);
                                                upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                            }
                                        }
                                    }
                                }

                            }
                            if (isExistOverDueUpkeepFlag) {
                                pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 2);
                            } else {
                                pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 1);
                            }
                        } else {
                            //保养标志设置为正常 1
                            pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 1);
                        }
                    }
                }

                // 根据设备资产获取所有设备 保养记录，只要有保养记录 不等于1且is_current = 1的，均需要把设别状态改为2
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    String assetNumber = pcbaDevice.getAssetNumber();
                    if (assetNumber != null && !"".equals(assetNumber)) {
                        /*Integer numByAssetNumber = upkeepHistoryDao.getNumByAssetNumber(assetNumber);
                        if(numByAssetNumber == 0){
                            pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 1);
                        }else{
                            Integer numByAssetNumber2 = upkeepHistoryDao.getNumByAssetNumber2(assetNumber);
                            if(numByAssetNumber2 != 0){
                                pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 2);
                            }
                        }*/
                        Integer numByAssetNumberOverdue = upkeepHistoryDao.getNumByAssetNumberOverdue(assetNumber);
                        if (numByAssetNumberOverdue > 0) {
                            pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 2);
                        } else {
                            pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 1);
                        }
                    }
                }
            } else {
                //刷新当前
                PcbaDevice pcbaDevice = pcbaDeviceDao.getById(pcbaDeviceId);
                if (pcbaDevice != null) {
                    boolean isExistOverDueUpkeepFlag = false;
                    String assetNumber = pcbaDevice.getAssetNumber();
                    if (assetNumber != null && !"".equals(assetNumber)) {
                        List<Upkeep> upkeepList = upkeepDao.getUpkeepByDeviceId(pcbaDevice.getAssetNumber(), null);
                        if (upkeepList.size() > 0) {
                            // 需要对比判断保养记录
                            for (Upkeep upkeep : upkeepList) {
                                Date firstUpkeepTime = upkeep.getFirstUpkeepTime();
                                Integer upkeepType = upkeep.getUpkeepType();
                                List<String> monthBetweenDate = CommonUtils.getMonthBetweenDate(firstUpkeepTime, new Date());

                                for (int a = 0; a < monthBetweenDate.size(); a++) {
                                    List<UpkeepHistory> upkeepHistoryList = upkeepHistoryDao.getUpkeepHistoryByAssetNumberAndDueUpkeepTime(assetNumber, upkeepType, monthBetweenDate.get(a));
                                    if (upkeepHistoryList.size() > 0) {
                                        // 存在保养计划的情况下，需要更新原先的保养记录
                                        // 比如
                                        // 1.超过三天的需要改为逾期 【放入2.逻辑判断】
                                        /*for (UpkeepHistory upkeepHistory : upkeepHistoryList) {
                                            Long num = CommonUtils.getDaysBetweenTwoDate(upkeepHistory.getDueUpkeepTime(), new Date());
                                            if(upkeepHistory.getStatus() == 4){
                                                if(num > delayDay){
                                                    // 大于 delayDay 改为  逾期状态 即 5
                                                    UpkeepHistory updateUpkeepHistory = new UpkeepHistory();
                                                    updateUpkeepHistory.setUpkeepHistoryId(upkeepHistory.getUpkeepHistoryId());
                                                    updateUpkeepHistory.setUpdateTime(new Date());
                                                    updateUpkeepHistory.setStatus(5);
                                                    upkeepHistoryDao.updateUpkeepHistoryById(updateUpkeepHistory);
                                                }
                                            }
                                        }*/
                                        // 2.到达下一个节点的需要新增一个记录
                                        if (upkeepType == 1) {
                                            Calendar calendar = Calendar.getInstance();
                                            calendar.setTime(firstUpkeepTime);
                                            calendar.add(Calendar.MONTH, a);//增加1个月
                                            Date time = calendar.getTime();

                                            // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                            int status = 4;
                                            long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                            if (daysBetweenTwoDate > delayDay) {
                                                status = 5;
                                                isExistOverDueUpkeepFlag = true;
                                            }

                                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                                            List<UpkeepHistory> upkeepHistoryByAssetNumberAndMonthAndUpkeepType = upkeepHistoryDao.getUpkeepHistoryByAssetNumberAndMonthAndUpkeepType(assetNumber, 1, sdf.format(time));
                                            if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType != null && upkeepHistoryByAssetNumberAndMonthAndUpkeepType.size() > 0) {
                                                // 存在了 判断有没有超期（状态为4超期的需要改为 5）
                                                Long num = CommonUtils.getDaysBetweenTwoDate(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getDueUpkeepTime(), new Date());
                                                if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getStatus() == 4) {
                                                    if (num > delayDay) {
                                                        // 大于 delayDay 改为  逾期状态 即 5
                                                        UpkeepHistory updateUpkeepHistory = new UpkeepHistory();
                                                        updateUpkeepHistory.setUpkeepHistoryId(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getUpkeepHistoryId());
                                                        updateUpkeepHistory.setUpdateTime(new Date());
                                                        updateUpkeepHistory.setStatus(5);
                                                        upkeepHistoryDao.updateUpkeepHistoryById(updateUpkeepHistory);
                                                    }
                                                }
                                            } else {
                                                // 不存在，新增
                                                UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                addUpkeepHistory.setAssetNumber(assetNumber);
                                                addUpkeepHistory.setCreateTime(new Date());
                                                addUpkeepHistory.setStatus(status);
                                                addUpkeepHistory.setDueUpkeepTime(time);
                                                addUpkeepHistory.setUpkeepType(upkeepType);
                                                addUpkeepHistory.setIsCurrent(1);
                                                upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                            }

                                        } else if (upkeepType == 2) {
                                            if (a % 3 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加3个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                                                List<UpkeepHistory> upkeepHistoryByAssetNumberAndMonthAndUpkeepType = upkeepHistoryDao.getUpkeepHistoryByAssetNumberAndMonthAndUpkeepType(assetNumber, 2, sdf.format(time));
                                                if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType != null && upkeepHistoryByAssetNumberAndMonthAndUpkeepType.size() > 0) {
                                                    // 存在了 判断有没有超期（状态为4超期的需要改为 5）
                                                    Long num = CommonUtils.getDaysBetweenTwoDate(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getDueUpkeepTime(), new Date());
                                                    if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getStatus() == 4) {
                                                        if (num > delayDay) {
                                                            // 大于 delayDay 改为  逾期状态 即 5
                                                            UpkeepHistory updateUpkeepHistory = new UpkeepHistory();
                                                            updateUpkeepHistory.setUpkeepHistoryId(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getUpkeepHistoryId());
                                                            updateUpkeepHistory.setUpdateTime(new Date());
                                                            updateUpkeepHistory.setStatus(5);
                                                            upkeepHistoryDao.updateUpkeepHistoryById(updateUpkeepHistory);
                                                        }
                                                    }
                                                } else {
                                                    UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                    addUpkeepHistory.setAssetNumber(assetNumber);
                                                    addUpkeepHistory.setCreateTime(new Date());
                                                    addUpkeepHistory.setStatus(status);
                                                    addUpkeepHistory.setDueUpkeepTime(time);
                                                    addUpkeepHistory.setUpkeepType(upkeepType);
                                                    addUpkeepHistory.setIsCurrent(1);
                                                    upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                                }
                                            }
                                        } else if (upkeepType == 3) {
                                            if (a % 6 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加6个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                                                List<UpkeepHistory> upkeepHistoryByAssetNumberAndMonthAndUpkeepType = upkeepHistoryDao.getUpkeepHistoryByAssetNumberAndMonthAndUpkeepType(assetNumber, 3, sdf.format(time));
                                                if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType != null && upkeepHistoryByAssetNumberAndMonthAndUpkeepType.size() > 0) {
                                                    // 存在了 判断有没有超期（状态为4超期的需要改为 5）
                                                    Long num = CommonUtils.getDaysBetweenTwoDate(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getDueUpkeepTime(), new Date());
                                                    if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getStatus() == 4) {
                                                        if (num > delayDay) {
                                                            // 大于 delayDay 改为  逾期状态 即 5
                                                            UpkeepHistory updateUpkeepHistory = new UpkeepHistory();
                                                            updateUpkeepHistory.setUpkeepHistoryId(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getUpkeepHistoryId());
                                                            updateUpkeepHistory.setUpdateTime(new Date());
                                                            updateUpkeepHistory.setStatus(5);
                                                            upkeepHistoryDao.updateUpkeepHistoryById(updateUpkeepHistory);
                                                        }
                                                    }
                                                } else {
                                                    UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                    addUpkeepHistory.setAssetNumber(assetNumber);
                                                    addUpkeepHistory.setCreateTime(new Date());
                                                    addUpkeepHistory.setStatus(status);
                                                    addUpkeepHistory.setDueUpkeepTime(time);
                                                    addUpkeepHistory.setUpkeepType(upkeepType);
                                                    addUpkeepHistory.setIsCurrent(1);
                                                    upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                                }
                                            }
                                        } else {
                                            if (a % 12 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加12个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                                                List<UpkeepHistory> upkeepHistoryByAssetNumberAndMonthAndUpkeepType = upkeepHistoryDao.getUpkeepHistoryByAssetNumberAndMonthAndUpkeepType(assetNumber, 4, sdf.format(time));
                                                if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType != null && upkeepHistoryByAssetNumberAndMonthAndUpkeepType.size() > 0) {
                                                    // 存在了 判断有没有超期（状态为4超期的需要改为 5）
                                                    Long num = CommonUtils.getDaysBetweenTwoDate(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getDueUpkeepTime(), new Date());
                                                    if (upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getStatus() == 4) {
                                                        if (num > delayDay) {
                                                            // 大于 delayDay 改为  逾期状态 即 5
                                                            UpkeepHistory updateUpkeepHistory = new UpkeepHistory();
                                                            updateUpkeepHistory.setUpkeepHistoryId(upkeepHistoryByAssetNumberAndMonthAndUpkeepType.get(0).getUpkeepHistoryId());
                                                            updateUpkeepHistory.setUpdateTime(new Date());
                                                            updateUpkeepHistory.setStatus(5);
                                                            upkeepHistoryDao.updateUpkeepHistoryById(updateUpkeepHistory);
                                                        }
                                                    }
                                                } else {
                                                    UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                    addUpkeepHistory.setAssetNumber(assetNumber);
                                                    addUpkeepHistory.setCreateTime(new Date());
                                                    addUpkeepHistory.setStatus(status);
                                                    addUpkeepHistory.setDueUpkeepTime(time);
                                                    addUpkeepHistory.setUpkeepType(upkeepType);
                                                    addUpkeepHistory.setIsCurrent(1);
                                                    upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                                }
                                            }
                                        }

                                    } else {
                                        // 不存在保养记录[插入表，状态需判断是否超期，超期改5，正常改4]  asset_number,create_time,status,due_upkeep_time,upkeep_type
                                        if (upkeepType == 1) {
                                            Calendar calendar = Calendar.getInstance();
                                            calendar.setTime(firstUpkeepTime);
                                            calendar.add(Calendar.MONTH, a);//增加1个月
                                            Date time = calendar.getTime();

                                            // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                            int status = 4;
                                            long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                            if (daysBetweenTwoDate > delayDay) {
                                                status = 5;
                                                isExistOverDueUpkeepFlag = true;
                                            }

                                            UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                            addUpkeepHistory.setAssetNumber(assetNumber);
                                            addUpkeepHistory.setCreateTime(new Date());
                                            addUpkeepHistory.setStatus(status);
                                            addUpkeepHistory.setDueUpkeepTime(time);
                                            addUpkeepHistory.setUpkeepType(upkeepType);
                                            addUpkeepHistory.setIsCurrent(1);
                                            upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                        } else if (upkeepType == 2) {
                                            if (a % 3 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加3个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                addUpkeepHistory.setAssetNumber(assetNumber);
                                                addUpkeepHistory.setCreateTime(new Date());
                                                addUpkeepHistory.setStatus(status);
                                                addUpkeepHistory.setDueUpkeepTime(time);
                                                addUpkeepHistory.setUpkeepType(upkeepType);
                                                addUpkeepHistory.setIsCurrent(1);
                                                upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                            }
                                        } else if (upkeepType == 3) {
                                            if (a % 6 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加6个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                addUpkeepHistory.setAssetNumber(assetNumber);
                                                addUpkeepHistory.setCreateTime(new Date());
                                                addUpkeepHistory.setStatus(status);
                                                addUpkeepHistory.setDueUpkeepTime(time);
                                                addUpkeepHistory.setUpkeepType(upkeepType);
                                                addUpkeepHistory.setIsCurrent(1);
                                                upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                            }
                                        } else {
                                            if (a % 12 == 0) {
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTime(firstUpkeepTime);
                                                calendar.add(Calendar.MONTH, a);//增加12个月
                                                Date time = calendar.getTime();

                                                // 判断与当前时间差是否在 delayDay 之间 ，是的话状态4，不是的话状态5
                                                int status = 4;
                                                long daysBetweenTwoDate = CommonUtils.getDaysBetweenTwoDate(time, new Date());
                                                if (daysBetweenTwoDate > delayDay) {
                                                    status = 5;
                                                    isExistOverDueUpkeepFlag = true;
                                                }

                                                UpkeepHistory addUpkeepHistory = new UpkeepHistory();
                                                addUpkeepHistory.setAssetNumber(assetNumber);
                                                addUpkeepHistory.setCreateTime(new Date());
                                                addUpkeepHistory.setStatus(status);
                                                addUpkeepHistory.setDueUpkeepTime(time);
                                                addUpkeepHistory.setUpkeepType(upkeepType);
                                                addUpkeepHistory.setIsCurrent(1);
                                                upkeepHistoryDao.addUpkeepHistory(addUpkeepHistory);
                                            }
                                        }
                                    }
                                }

                            }
                            if (isExistOverDueUpkeepFlag) {
                                pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 2);
                            } else {
                                pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 1);
                            }
                        } else {
                            //保养标志设置为正常 1
                            pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 1);
                        }
                    }

                    // 根据设备资产获取所有设备 保养记录，只要有保养记录 不等于1且is_current = 1的，均需要把设别状态改为2
                    if (assetNumber != null && !"".equals(assetNumber)) {
                        /*Integer numByAssetNumber = upkeepHistoryDao.getNumByAssetNumber(assetNumber);
                        if(numByAssetNumber == 0){
                            pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 1);
                        }else{
                            Integer numByAssetNumber2 = upkeepHistoryDao.getNumByAssetNumber2(assetNumber);
                            if(numByAssetNumber2 != 0){
                                pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 2);
                            }
                        }*/
                        Integer numByAssetNumberOverdue = upkeepHistoryDao.getNumByAssetNumberOverdue(assetNumber);
                        if (numByAssetNumberOverdue > 0) {
                            pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 2);
                        } else {
                            pcbaDeviceDao.updateDeviceUpkeepStatus(assetNumber, 1);
                        }
                    }
                } else {
                    return ResultUtil.error(500, "未找到pcbaDevice", "Not Found pcbaDevice", null);
                }
            }
            return ResultUtil.success(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result refreshDeviceTechCapacityOverdueValidity() {
        try {
            List<PcbaDevice> allPcbaDevice = pcbaDeviceDao.getAllPcbaDevice(null, null, null, null, null, null, null, null, null, null);

            List<PcbaDevice> oldList = new ArrayList<>();
            List<PcbaDevice> newList = new ArrayList<>();
            Date d = new Date();
            for (PcbaDevice pcbaDevice : allPcbaDevice) {
                Integer pcbaDeviceId = pcbaDevice.getPcbaDeviceId();
                Integer paramsStatus = pcbaDevice.getParamsStatus();

                Date endTime = pcbaDevice.getEndTime();

                if (endTime != null) {
                    int compareTo = endTime.compareTo(d);
                    if (compareTo < 1) {
                        // 过期了
                        if (paramsStatus != 5) {
                            oldList.add(pcbaDevice);
                            // update
                            PcbaDevice updatePcbaDevice = new PcbaDevice();
                            updatePcbaDevice.setUpdateTime(d);
                            updatePcbaDevice.setParamsStatus(5);
                            updatePcbaDevice.setPcbaDeviceId(pcbaDeviceId);
                            pcbaDeviceDao.updatePcbaDevice(updatePcbaDevice);
                            // 如果过期了，需要将所在的线体的 实际认证能力改为6
                            Integer pcbaLineId = pcbaDevice.getPcbaLineId();
                            pcbaLineDao.auditPcbaLineParamTechActual(pcbaLineId, 6, "");

                            // 添加 审核记录
                            AuditHistory addAuditHistory = new AuditHistory();
                            addAuditHistory.setAuditType(1);
                            addAuditHistory.setCreateTime(d);
                            addAuditHistory.setSubmitUserId(null);
                            addAuditHistory.setAuditUserId(null);
                            addAuditHistory.setAuditStatus(5);
                            addAuditHistory.setAuditNotes(null);
                            addAuditHistory.setRelatedId(pcbaDeviceId);
                            auditHistoryDao.addAuditHistory(addAuditHistory);

                            newList.add(updatePcbaDevice);
                        }
                    }
                }
            }

            if (newList.size() > 0 || oldList.size() > 0) {
                // 操作日志
                operateService.addOperate(new Operate(1, null, operateSmallType, 3, 3, d, JSONObject.toJSONString(oldList), JSONObject.toJSONString(newList)));
            }

            return ResultUtil.success(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result refreshSpecialTechCapacityOverdueValidity() {
        try {
            List<PcbaSpecialResource> allPcbaSpecialResource = pcbaSpecialResourceDao.getAllByDeviceTypeAndSearch(null, null, null, null, null, null, null);

            List<PcbaSpecialResource> oldList = new ArrayList<>();
            List<PcbaSpecialResource> newList = new ArrayList<>();
            Date d = new Date();
            for (PcbaSpecialResource pcbaSpecialResource : allPcbaSpecialResource) {
                Integer pcbaSpecialResourceId = pcbaSpecialResource.getPcbaSpecialResourceId();
                Integer status = pcbaSpecialResource.getStatus();

                Date endTime = pcbaSpecialResource.getEndTime();

                if (endTime != null) {
                    int compareTo = endTime.compareTo(d);
                    if (compareTo < 1) {
                        // 过期了
                        if (status != 5) {
                            oldList.add(pcbaSpecialResource);
                            // update
                            PcbaSpecialResource updatePcbaSpecialResource = new PcbaSpecialResource();
                            updatePcbaSpecialResource.setUpdateTime(d);
                            updatePcbaSpecialResource.setStatus(5);
                            updatePcbaSpecialResource.setPcbaSpecialResourceId(pcbaSpecialResourceId);
                            pcbaSpecialResourceDao.updatePcbaSpecialResource(updatePcbaSpecialResource);

                            // 添加 审核记录
                            AuditHistory addAuditHistory = new AuditHistory();
                            addAuditHistory.setAuditType(2);
                            addAuditHistory.setCreateTime(d);
                            addAuditHistory.setSubmitUserId(null);
                            addAuditHistory.setAuditUserId(null);
                            addAuditHistory.setAuditStatus(5);
                            addAuditHistory.setAuditNotes(null);
                            addAuditHistory.setRelatedId(pcbaSpecialResourceId);
                            auditHistoryDao.addAuditHistory(addAuditHistory);

                            newList.add(updatePcbaSpecialResource);
                        }
                    }
                }
            }

            if (newList.size() > 0 || oldList.size() > 0) {
                // 操作日志
                operateService.addOperate(new Operate(1, null, operateSmallType, 3, 3, d, JSONObject.toJSONString(oldList), JSONObject.toJSONString(newList)));
            }

            return ResultUtil.success(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result refreshLineTechCapacityOverdueValidity() {
        try {
            List<PcbaLine> allPcbaLine = pcbaLineDao.getAllPcbaLine(null, null, null, null, null, null, null, null, null, null, null);

            List<PcbaLine> oldList = new ArrayList<>();
            List<PcbaLine> newList = new ArrayList<>();
            Date d = new Date();
            for (PcbaLine pcbaLine : allPcbaLine) {
                Integer pcbaLineId = pcbaLine.getPcbaLineId();
                Integer paramsStatusActual = pcbaLine.getParamsStatusActual();

                Date endTime = pcbaLine.getEndTimeActual();

                if (endTime != null) {
                    int compareTo = endTime.compareTo(d);
                    if (compareTo < 1) {
                        // 过期了
                        if (paramsStatusActual != 5 && paramsStatusActual != 6) {
                            oldList.add(pcbaLine);
                            // update
                            PcbaLine updatePcbaLine = new PcbaLine();
                            updatePcbaLine.setUpdateTime(d);
                            updatePcbaLine.setParamsStatusActual(5);
                            updatePcbaLine.setPcbaLineId(pcbaLineId);
                            pcbaLineDao.updatePcbaLine(updatePcbaLine);

                            // 添加 审核记录
                            AuditHistory addAuditHistory = new AuditHistory();
                            addAuditHistory.setAuditType(3);
                            addAuditHistory.setCreateTime(d);
                            addAuditHistory.setSubmitUserId(null);
                            addAuditHistory.setAuditUserId(null);
                            addAuditHistory.setAuditStatus(5);
                            addAuditHistory.setAuditNotes(null);
                            addAuditHistory.setRelatedId(pcbaLineId);
                            auditHistoryDao.addAuditHistory(addAuditHistory);

                            newList.add(updatePcbaLine);
                        }
                    }
                }
            }

            if (newList.size() > 0 || oldList.size() > 0) {
                // 操作日志
                operateService.addOperate(new Operate(1, null, operateSmallType, 3, 3, d, JSONObject.toJSONString(oldList), JSONObject.toJSONString(newList)));
            }

            return ResultUtil.success(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result sendEmailsForOverdue() {
        try {
            List<PcbaLine> allPcbaLine = pcbaLineDao.getAllPcbaLine(null, null, null, null, null, null, null, null, null, null, null);
            for (PcbaLine pcbaLine : allPcbaLine) {
                Integer paramsStatusActual = pcbaLine.getParamsStatusActual();
                Integer pcbaCompanyId = pcbaLine.getPcbaCompanyId();
                Integer pcbaWorkshopId = pcbaLine.getPcbaWorkshopId();
                PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaCompanyId);
                PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaWorkshopId);
                String emailOwners5 = pcbaCompany.getEmailOwners5();
                List<User> userList = new ArrayList<>();
                if (emailOwners5 != null && !"".equals(emailOwners5)) {
                    String[] split1 = emailOwners5.split(",");
                    for (String s : split1) {
                        if (s != null && !"".equals(s)) {
                            String[] split2 = s.split("\\/");
                            String domainAccount = split2[1];
                            User user = userDao.getUserInfoByDomainAccount(domainAccount);
                            if (user != null) {
                                userList.add(user);
                            }
                        }
                    }
                }
                if (userList.size() > 0) {
                    List<MailAddress> mailAddressList = new ArrayList<>();
                    for (User user : userList) {
                        if(user.getEmail().contains(",")){
                            String[] emailsArr = user.getEmail().split(",");
                            for (String email : emailsArr) {
                                MailAddress mailAddress = new MailAddress();
                                mailAddress.setMailAddress(email);
                                mailAddress.setType(0);
                                mailAddressList.add(mailAddress);
                            }
                        }else{
                            MailAddress mailAddress = new MailAddress();
                            mailAddress.setMailAddress(user.getEmail());
                            mailAddress.setType(0);
                            mailAddressList.add(mailAddress);
                        }
                    }
                    if (paramsStatusActual == 5) {
                        String mailContent = "<html><body>" +
                                "<p>主题：" + DB1EmailTemplates.OVERDUE_TECH_LINE_LINE_CONTENT + "</p>" +
                                "<p>线体信息：" + pcbaCompany.getPcbaCompanyNameCn() + "/" + pcbaWorkshop.getPcbaWorkshopNameCn() + "/" + pcbaLine.getPcbaLineNameCn() + "</p>" +
                                "<p>网页链接：<a href='" + trustedRedirectUri + DB1EmailTemplates.OVERDUE_TECH_LINE_LINE_WEB_URL + "'>点击跳转</a></p>" +
                                "</body></html>";
                        // 线体超期
                        Result result = thirdApiService.sendMail("", DB1EmailTemplates.OVERDUE_TECH_LINE_TITLE_OK, DB1EmailTemplates.OVERDUE_TECH_LINE_CONTENT_TITLE,
                                mailContent, "10086", mailAddressList, null, null, null, null, 2, null);
                        if (result.getCode() == 200) {
                            System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                            System.out.println("线体实际工艺认证超期定时发邮件,发送成功");
                        } else {
                            System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                            System.out.println("线体实际工艺认证超期定时发邮件,发送失败:" + result.getMsgCn());
                        }
                    }
                    if (paramsStatusActual == 6) {
                        String mailContent = "<html><body>" +
                                "<p>主题：" + DB1EmailTemplates.OVERDUE_TECH_LINE_DEVICE_LINE_CONTENT + "</p>" +
                                "<p>线体信息：" + pcbaCompany.getPcbaCompanyNameCn() + "/" + pcbaWorkshop.getPcbaWorkshopNameCn() + "/" + pcbaLine.getPcbaLineNameCn() + "</p>" +
                                "<p>网页链接：<a href='" + trustedRedirectUri + DB1EmailTemplates.OVERDUE_TECH_LINE_DEVICE_LINE_WEB_URL + "'>点击跳转</a></p>" +
                                "</body></html>";
                        // 线体下面设备超期
                        Result result = thirdApiService.sendMail("", DB1EmailTemplates.OVERDUE_TECH_LINE_DEVICE_TITLE_OK, DB1EmailTemplates.OVERDUE_TECH_LINE_DEVICE_CONTENT_TITLE,
                                mailContent, "10086", mailAddressList, null, null, null, null, 2, null);
                        if (result.getCode() == 200) {
                            System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                            System.out.println("线体下面设备实际工艺能力超期定时发邮件,发送成功");
                        } else {
                            System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                            System.out.println("线体下面设备实际工艺能力超期定时发邮件,发送失败:" + result.getMsgCn());
                        }
                    }
                }
            }
            return ResultUtil.success(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }


    /**
     * 级联改变所有相关参数值【重要逻辑】
     * type =
     * 1_1 修改基线能力参数池，需要判断基线参数值是否填写完整，修改是否完善基线参数信息字段
     * 1_2 修改工艺能力参数池，需要判断工艺参数值是否填写完整，修改是否完善工艺参数信息字段
     * 1_3 改变设备基线能力的值后触发，若工艺宣称值来源于基线，则需要修改宣称值；若工艺实际值等于宣称值，则需进一步修改。同时需要触发整线能力的修改（包含基线整线和工艺整线）
     * 1_4 改变设备工艺能力的宣称值后触发，修改实际能力和认证状态
     * 1_5 改变整线基线参数池（暂无需要处理逻辑）
     * 1_6 改变整线工艺参数池 需要判断线体对应的能力值是否填写完整，同步修改是否填写宣称能力、是否填写实际能力，以及两者的认证状态
     * 1_7 改变整线基线能力值 需要重新计算线体的宣称能力和实际能力，以及两者的认证状态
     * 1_8 改变整线工艺能力值 需要重新计算线体的实际能力，并修改认证状态
     */
    @Override
    public void cascadeChangeAllParams(String typeStr, Integer pcbaDeviceTypeId, Integer lineId) {
        Date d = new Date();
        List<PcbaDeviceResource> pcbaDeviceResourceList = pcbaDeviceResourceDao.getAllByDeviceTypeAndSearch(null, pcbaDeviceTypeId, null, null, null, null, null, null, null, null, null, null);
        if ("1_1".equals(typeStr)) {
            //改变基线能力参数池后需要触发，校验 是否完善基线参数信息
            for (PcbaDeviceResource pcbaDeviceResource : pcbaDeviceResourceList) {
                Boolean isFilled = true;
                List<PcbaDeviceParam> allPcbaDeviceParam = pcbaDeviceParamDao.getAllPcbaDeviceParam(pcbaDeviceTypeId, null, null);
                for (PcbaDeviceParam pcbaDeviceParam : allPcbaDeviceParam) {
                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(pcbaDeviceParam.getPcbaDeviceParamKey(), pcbaDeviceResource.getPcbaDeviceResourceId());
                    if (pcbaDeviceRelatedDeviceParam == null) {
                        isFilled = false;
                        break;
                    }
                }
                PcbaDeviceResource updatePcbaDeviceResource = new PcbaDeviceResource();
                updatePcbaDeviceResource.setUpdateTime(d);
                updatePcbaDeviceResource.setPcbaDeviceResourceId(pcbaDeviceResource.getPcbaDeviceResourceId());
                if (isFilled) {
                    updatePcbaDeviceResource.setIsFilledBaseParams(1);
                } else {
                    updatePcbaDeviceResource.setIsFilledBaseParams(2);
                }
                pcbaDeviceResourceDao.updatePcbaDeviceResource(updatePcbaDeviceResource);
            }
        } else if ("1_2".equals(typeStr)) {
            //改变工艺能力参数池后需要触发，校验 是否完善工艺参数信息
            for (PcbaDeviceResource pcbaDeviceResource : pcbaDeviceResourceList) {
                Boolean isFilled = true;
                List<TechDeviceParam> allTechDeviceParam = techDeviceParamDao.getAllTechDeviceParam(pcbaDeviceTypeId, null, null);
                for (TechDeviceParam techDeviceParam : allTechDeviceParam) {
                    PcbaDeviceRelatedTechParam pcbaDeviceRelatedTechParam = pcbaDeviceRelatedTechParamDao.getPcbaDeviceRelatedTechParamByKeyAndDeviceResourceId(techDeviceParam.getTechDeviceParamKey(), pcbaDeviceResource.getPcbaDeviceResourceId());
                    if (pcbaDeviceRelatedTechParam == null) {
                        isFilled = false;
                        break;
                    }
                }
                PcbaDeviceResource updatePcbaDeviceResource = new PcbaDeviceResource();
                updatePcbaDeviceResource.setUpdateTime(d);
                updatePcbaDeviceResource.setPcbaDeviceResourceId(pcbaDeviceResource.getPcbaDeviceResourceId());
                if (isFilled) {
                    updatePcbaDeviceResource.setIsFilledTechParams(1);
                } else {
                    updatePcbaDeviceResource.setIsFilledTechParams(2);
                }
                pcbaDeviceResourceDao.updatePcbaDeviceResource(updatePcbaDeviceResource);
            }
        }/*else if("1_3".equals(typeStr)){
            //改变设备基线能力的值后触发，若工艺宣称值来源于基线，则需要修改宣称值；若工艺实际值等于宣称值，则需进一步修改。同时需要触发整线能力的修改（包含基线整线和工艺整线）
            for (PcbaDeviceResource pcbaDeviceResource : pcbaDeviceResourceList) {
                List<TechDeviceParam> allTechDeviceParam = techDeviceParamDao.getAllTechDeviceParam(pcbaDeviceTypeId, null, null);
                for (TechDeviceParam techDeviceParam : allTechDeviceParam) {
                    Integer techDeviceParamId = techDeviceParam.getTechDeviceParamId();
                    String bindDeviceParamKey = techDeviceParam.getBindDeviceParamKey();
                    Integer techDeviceParamFillType = techDeviceParam.getTechDeviceParamFillType();
                    Integer actualEqualDeclare = techDeviceParam.getActualEqualDeclare();
                    String techDeviceParamKey = techDeviceParam.getTechDeviceParamKey();

                    // 修改设备能力的工艺宣称值和实际值
                    changeDeviceDeclareCapacityAndStatus(techDeviceParamFillType,
                            bindDeviceParamKey,
                            d,
                            actualEqualDeclare,
                            techDeviceParamKey,
                            pcbaDeviceResource
                            );

                    //修改基线的整线能力并同时修改工艺的整线能力和认证状态（宣称+实际）
                    *//*1：取最大值
                    2：取最小值
                    3：取当前值
                    4：取最小值[特殊，取前两位判断大小]
                    5：取最大值[特殊，取前两位判断大小]
                    6：取和值
                    7：只要有一台为”是“，则为是；全部”否“，则为”否“
                    8：只要任意一台填写”有“，则为”有“*//*

                    List<BaseCapacityRule> baseCapacityRuleList = baseCapacityRuleDao.getAllBaseCapacityRule(null, null, null);
                    List<PcbaLine> pcbaLineList = pcbaLineDao.getAllPcbaLine(null,null,null,null,null,null,null,null,null);
                    List<TechCapacityRule> techCapacityRuleList = techCapacityRuleDao.getAllTechCapacityRule(null, null, null);

                    // 1、修改整线基线能力
                    changePcbaLineBaseCapacity(pcbaLineList,
                            baseCapacityRuleList,
                            d
                    );

                    // 2、检索 线体的宣称工艺能力是否来自于基线整线能力，有的话需要修改值以及认证状态
                    changePcbaLineDeclareAndActualTechCapacity(pcbaLineList,
                            techCapacityRuleList,
                            d
                    );
                }
            }
        }else if("1_4".equals(typeStr)) {
            //改变设备工艺能力的宣称值后触发，修改实际能力和认证状态
            List<TechDeviceParam> techDeviceParamList = techDeviceParamDao.getAllTechDeviceParam(pcbaDeviceTypeId, null, null);
            List<PcbaDeviceResource> pcbaDeviceResources = pcbaDeviceResourceDao.getAllByDeviceTypeAndSearch(null, pcbaDeviceTypeId, null, null, null, null, null, null, null);
            for (PcbaDeviceResource pcbaDeviceResource : pcbaDeviceResources) {
                Integer pcbaDeviceResourceId = pcbaDeviceResource.getPcbaDeviceResourceId();
                for (TechDeviceParam techDeviceParam : techDeviceParamList) {
                    Integer actualEqualDeclare = techDeviceParam.getActualEqualDeclare();
                    String techDeviceParamKey = techDeviceParam.getTechDeviceParamKey();
                    PcbaDeviceRelatedTechParam pcbaDeviceRelatedTechParam = pcbaDeviceRelatedTechParamDao.getPcbaDeviceRelatedTechParamByKeyAndDeviceResourceId(techDeviceParamKey, pcbaDeviceResourceId);
                    if(pcbaDeviceRelatedTechParam != null){
                        String techDeviceParamValue = pcbaDeviceRelatedTechParam.getTechDeviceParamValue();
                        changeDeviceActualCapacityAndStatus(actualEqualDeclare,
                                d,
                                techDeviceParamValue,
                                techDeviceParamKey
                        );
                    }
                }
            }
        }else if("1_5".equals(typeStr)){
            //改变整线基线参数池（暂无需要处理逻辑）
        }else if("1_6".equals(typeStr)){
            //改变整线工艺参数池 需要判断线体对应的能力值是否填写完整，同步修改是否填写宣称能力、是否填写实际能力，以及两者的认证状态

        }else if("1_7".equals(typeStr)){
            //改变整线基线能力值 需要重新计算线体的宣称能力和实际能力，以及两者的认证状态
            PcbaLine pcbaLineById = pcbaLineDao.getPcbaLineById(lineId);
            if(pcbaLineById != null){
                List<PcbaLine> pcbaLineList = new ArrayList<>();
                pcbaLineList.add(pcbaLineById);
                List<TechCapacityRule> techCapacityRuleList = techCapacityRuleDao.getAllTechCapacityRule(null, null, null);
                changePcbaLineDeclareAndActualTechCapacity(pcbaLineList,
                        techCapacityRuleList,
                        d
                );
            }

        }else if("1_8".equals(typeStr)){
            //改变整线工艺能力值 需要重新计算线体的实际能力，并修改认证状态
            changePcbaLineActualTechCapacity(lineId, d);
        }*/
    }

    /**
     * 改变基线参数池触发 -> 校验设备的基线参数是否填写完整
     */
    @Override
    public void changeBaseDeviceResourceStatus(Integer pcbaDeviceTypeId) {
        List<PcbaDeviceResource> pcbaDeviceResourceList = pcbaDeviceResourceDao.getAllByDeviceTypeAndSearch(null, pcbaDeviceTypeId, null, null, null, null, null, null, null, null, null, null);
        for (PcbaDeviceResource pcbaDeviceResource : pcbaDeviceResourceList) {
            Integer pcbaDeviceResourceId = pcbaDeviceResource.getPcbaDeviceResourceId();
            Boolean b = true;
            List<PcbaDeviceParam> pcbaDeviceParamList = pcbaDeviceParamDao.getAllPcbaDeviceParam(pcbaDeviceTypeId, null, null);
            for (PcbaDeviceParam pcbaDeviceParam : pcbaDeviceParamList) {
                String pcbaDeviceParamKey = pcbaDeviceParam.getPcbaDeviceParamKey();
                Integer isRequired = pcbaDeviceParam.getIsRequired();
                if (isRequired == 1) {
                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(pcbaDeviceParamKey, pcbaDeviceResourceId);
                    if (pcbaDeviceRelatedDeviceParam == null || pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue() == null || "".equals(pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue())) {
                        b = false;
                        break;
                    }
                }
            }
            PcbaDeviceResource updatePcbaDeviceResource = new PcbaDeviceResource();
            updatePcbaDeviceResource.setUpdateTime(new Date());
            updatePcbaDeviceResource.setPcbaDeviceResourceId(pcbaDeviceResourceId);
            if (b) {
                updatePcbaDeviceResource.setIsFilledBaseParams(1);
            } else {
                updatePcbaDeviceResource.setIsFilledBaseParams(2);
            }
            pcbaDeviceResourceDao.updatePcbaDeviceResource(updatePcbaDeviceResource);
        }
    }

    /**
     * 改变工艺参数池触发 -> 校验设备的工艺参数是否填写完整
     */
    @Override
    public void changeTechDeviceResourceStatus(Integer pcbaDeviceTypeId) {
        List<PcbaDeviceResource> pcbaDeviceResourceList = pcbaDeviceResourceDao.getAllByDeviceTypeAndSearch(null, pcbaDeviceTypeId, null, null, null, null, null, null, null, null, null, null);
        for (PcbaDeviceResource pcbaDeviceResource : pcbaDeviceResourceList) {
            Integer pcbaDeviceResourceId = pcbaDeviceResource.getPcbaDeviceResourceId();
            Boolean b = true;
            List<TechDeviceParam> techDeviceParamList = techDeviceParamDao.getAllTechDeviceParam(pcbaDeviceTypeId, null, null);
            for (TechDeviceParam techDeviceParam : techDeviceParamList) {
                String techDeviceParamKey = techDeviceParam.getTechDeviceParamKey();
                Integer isRequired = techDeviceParam.getIsRequired();
                if (isRequired == 1) {
                    PcbaDeviceRelatedTechParam pcbaDeviceRelatedTechParam = pcbaDeviceRelatedTechParamDao.getPcbaDeviceRelatedTechParamByKeyAndDeviceResourceId(techDeviceParamKey, pcbaDeviceResourceId);
                    if (pcbaDeviceRelatedTechParam == null || pcbaDeviceRelatedTechParam.getTechDeviceParamValue() == null || "".equals(pcbaDeviceRelatedTechParam.getTechDeviceParamValue())) {
                        b = false;
                        break;
                    }
                }
            }
            PcbaDeviceResource updatePcbaDeviceResource = new PcbaDeviceResource();
            updatePcbaDeviceResource.setUpdateTime(new Date());
            updatePcbaDeviceResource.setPcbaDeviceResourceId(pcbaDeviceResourceId);
            if (b) {
                updatePcbaDeviceResource.setIsFilledTechParams(1);
            } else {
                updatePcbaDeviceResource.setIsFilledTechParams(2);
            }
            pcbaDeviceResourceDao.updatePcbaDeviceResource(updatePcbaDeviceResource);
        }
    }

    /**
     * 改变设备资源基线参数值触发以下变动
     * 1.设备资源工艺宣称参数值变动（部分宣称值来自于基线）
     * 2.设备资源工艺实际参数值变动（判断实际能力是否=宣称能力） 认证状态改为待提交认证
     * 3.线体整线基线能力重新计算
     * 4.线体整线工艺宣称能力重新计算（部分整线工艺能力来源于基线能力）认证状态改为待提交认证
     * 5.线体整线工艺实际能力变动（判断实际能力是否=宣称能力） 认证状态改为待提交认证
     */
    @Override
    public void changeDeviceResourceBaseParamValue(Integer pcbaDeviceResourceId, Date d, String userId) {
        if (pcbaDeviceResourceId != null) {
            List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceResourceByPcbaDeviceResourceId(pcbaDeviceResourceId);
            List<Integer> pcbaLineList = new ArrayList<>();
            List<PcbaDeviceRelatedTechParam> oldPcbaDeviceRelatedTechParamList = new ArrayList<>();
            List<PcbaDeviceRelatedTechParam> newPcbaDeviceRelatedTechParamList = new ArrayList<>();
            List<PcbaDeviceRelatedTechParamActual> oldPcbaDeviceRelatedTechParamActualList = new ArrayList<>();
            List<PcbaDeviceRelatedTechParamActual> newPcbaDeviceRelatedTechParamActualList = new ArrayList<>();
            for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                Integer pcbaDeviceId = pcbaDevice.getPcbaDeviceId();
                Integer pcbaDeviceTypeId = pcbaDevice.getPcbaDeviceTypeId();
                Integer pcbaLineId = pcbaDevice.getPcbaLineId();
                pcbaLineList.add(pcbaLineId);

                List<TechDeviceParam> techDeviceParamList = techDeviceParamDao.getAllTechDeviceParam(pcbaDeviceTypeId, null, null);
                for (TechDeviceParam techDeviceParam : techDeviceParamList) {
                    Integer actualEqualDeclare = techDeviceParam.getActualEqualDeclare();
                    String techDeviceParamKey = techDeviceParam.getTechDeviceParamKey();
                    String bindDeviceParamKey = techDeviceParam.getBindDeviceParamKey();
                    Integer techDeviceParamFillType = techDeviceParam.getTechDeviceParamFillType();
                /*4：来源基线
                5：取多个基线最小值*/
                    if (techDeviceParamFillType == 4 && bindDeviceParamKey != null && !"".equals(bindDeviceParamKey)) {
                        PcbaDeviceRelatedTechParam pcbaDeviceRelatedTechParam = pcbaDeviceRelatedTechParamDao.getPcbaDeviceRelatedTechParamByKeyAndDeviceResourceId(techDeviceParamKey, pcbaDeviceResourceId);
                        PcbaDeviceRelatedTechParamActual pcbaDeviceRelatedTechParamActual = pcbaDeviceRelatedTechParamActualDao.getPcbaDeviceRelatedTechParamActualByPcbaDeviceIdAndKey(pcbaDeviceId, techDeviceParamKey);
                        PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(bindDeviceParamKey, pcbaDeviceResourceId);
                        if (pcbaDeviceRelatedTechParam != null && pcbaDeviceRelatedDeviceParam != null) {
                            String techDeviceParamValue = pcbaDeviceRelatedTechParam.getTechDeviceParamValue();
                            String pcbaDeviceParamValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                            if (!techDeviceParamValue.equals(pcbaDeviceParamValue)) {
                                Integer pcbaDeviceRelatedTechParamId = pcbaDeviceRelatedTechParam.getPcbaDeviceRelatedTechParamId();
                                oldPcbaDeviceRelatedTechParamList.add(pcbaDeviceRelatedTechParam);
                                // update
                                PcbaDeviceRelatedTechParam updatePcbaDeviceRelatedTechParam = new PcbaDeviceRelatedTechParam();
                                updatePcbaDeviceRelatedTechParam.setUpdateTime(d);
                                updatePcbaDeviceRelatedTechParam.setTechDeviceParamValue(pcbaDeviceParamValue);
                                updatePcbaDeviceRelatedTechParam.setPcbaDeviceRelatedTechParamId(pcbaDeviceRelatedTechParamId);
                                pcbaDeviceRelatedTechParamDao.updateDeviceRelatedParam(updatePcbaDeviceRelatedTechParam);
                                newPcbaDeviceRelatedTechParamList.add(updatePcbaDeviceRelatedTechParam);

                                if (pcbaDeviceRelatedTechParamActual != null) {
                                    if (actualEqualDeclare != null && actualEqualDeclare == 1) {
                                        oldPcbaDeviceRelatedTechParamActualList.add(pcbaDeviceRelatedTechParamActual);
                                        Integer pcbaDeviceRelatedTechParamActualId = pcbaDeviceRelatedTechParamActual.getPcbaDeviceRelatedTechParamActualId();
                                        // update
                                        PcbaDeviceRelatedTechParamActual updatePcbaDeviceRelatedTechParamActual = new PcbaDeviceRelatedTechParamActual();
                                        updatePcbaDeviceRelatedTechParamActual.setPcbaDeviceRelatedTechParamActualId(pcbaDeviceRelatedTechParamActualId);
                                        updatePcbaDeviceRelatedTechParamActual.setTechDeviceParamValue(pcbaDeviceParamValue);
                                        updatePcbaDeviceRelatedTechParamActual.setUpdateTime(d);
                                        pcbaDeviceRelatedTechParamActualDao.updateDeviceRelatedParamActual(updatePcbaDeviceRelatedTechParamActual);
                                        newPcbaDeviceRelatedTechParamActualList.add(updatePcbaDeviceRelatedTechParamActual);
                                    }
                                }
                            }
                        }
                    } else if (techDeviceParamFillType == 5 && bindDeviceParamKey != null && !"".equals(bindDeviceParamKey)) {
                        PcbaDeviceRelatedTechParam pcbaDeviceRelatedTechParam = pcbaDeviceRelatedTechParamDao.getPcbaDeviceRelatedTechParamByKeyAndDeviceResourceId(techDeviceParamKey, pcbaDeviceResourceId);
                        PcbaDeviceRelatedTechParamActual pcbaDeviceRelatedTechParamActual = pcbaDeviceRelatedTechParamActualDao.getPcbaDeviceRelatedTechParamActualByPcbaDeviceIdAndKey(pcbaDeviceId, techDeviceParamKey);

                        String[] keyArr = bindDeviceParamKey.split(",");
                        String fV = "";
                        List<String> valueList = new ArrayList<>();
                        for (String key : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(key, pcbaDeviceResourceId);
                            if (pcbaDeviceRelatedDeviceParam != null && pcbaDeviceRelatedTechParam != null) {
                                valueList.add(pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue());
                            }
                        }
                        //取最小值
                        for (String s : valueList) {
                            if (CommonUtils.isNumeric(s)) {
                                if ("".equals(fV)) {
                                    fV = s;
                                } else {
                                    if (Double.parseDouble(fV) >= Double.parseDouble(s)) {
                                        fV = s;
                                    }
                                }
                            }
                        }
                        if (pcbaDeviceRelatedTechParam != null) {
                            String techDeviceParamValue = pcbaDeviceRelatedTechParam.getTechDeviceParamValue();
                            if (!techDeviceParamValue.equals(fV)) {
                                Integer pcbaDeviceRelatedTechParamId = pcbaDeviceRelatedTechParam.getPcbaDeviceRelatedTechParamId();
                                oldPcbaDeviceRelatedTechParamList.add(pcbaDeviceRelatedTechParam);
                                // update
                                PcbaDeviceRelatedTechParam updatePcbaDeviceRelatedTechParam = new PcbaDeviceRelatedTechParam();
                                updatePcbaDeviceRelatedTechParam.setUpdateTime(d);
                                updatePcbaDeviceRelatedTechParam.setTechDeviceParamValue(fV);
                                updatePcbaDeviceRelatedTechParam.setPcbaDeviceRelatedTechParamId(pcbaDeviceRelatedTechParamId);
                                pcbaDeviceRelatedTechParamDao.updateDeviceRelatedParam(updatePcbaDeviceRelatedTechParam);
                                newPcbaDeviceRelatedTechParamList.add(updatePcbaDeviceRelatedTechParam);

                                if (pcbaDeviceRelatedTechParamActual != null) {
                                    if (actualEqualDeclare != null && actualEqualDeclare == 1) {
                                        oldPcbaDeviceRelatedTechParamActualList.add(pcbaDeviceRelatedTechParamActual);
                                        Integer pcbaDeviceRelatedTechParamActualId = pcbaDeviceRelatedTechParamActual.getPcbaDeviceRelatedTechParamActualId();
                                        // update
                                        PcbaDeviceRelatedTechParamActual updatePcbaDeviceRelatedTechParamActual = new PcbaDeviceRelatedTechParamActual();
                                        updatePcbaDeviceRelatedTechParamActual.setPcbaDeviceRelatedTechParamActualId(pcbaDeviceRelatedTechParamActualId);
                                        updatePcbaDeviceRelatedTechParamActual.setTechDeviceParamValue(fV);
                                        updatePcbaDeviceRelatedTechParamActual.setUpdateTime(d);
                                        pcbaDeviceRelatedTechParamActualDao.updateDeviceRelatedParamActual(updatePcbaDeviceRelatedTechParamActual);
                                        newPcbaDeviceRelatedTechParamActualList.add(updatePcbaDeviceRelatedTechParamActual);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (oldPcbaDeviceRelatedTechParamList.size() > 0 || newPcbaDeviceRelatedTechParamList.size() > 0) {
                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 3, new Date(), JSONObject.toJSONString(oldPcbaDeviceRelatedTechParamList), JSONObject.toJSONString(newPcbaDeviceRelatedTechParamList)));
            }
            if (oldPcbaDeviceRelatedTechParamActualList.size() > 0 || newPcbaDeviceRelatedTechParamActualList.size() > 0) {
                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 3, new Date(), JSONObject.toJSONString(oldPcbaDeviceRelatedTechParamActualList), JSONObject.toJSONString(newPcbaDeviceRelatedTechParamActualList)));
            }

            for (Integer pcbaLineId : pcbaLineList) {
                changeLineDevice(pcbaLineId, d, userId);
            }
        }
    }

    /**
     * 改变设备工艺实际参数值引发
     * 暂无需要处理
     */
    @Override
    public void changeDeviceTechParamActualValue() {

    }

    /**
     * 改变线体设备
     * 1.线体整线基线能力重新计算
     * 2.线体整线工艺宣称能力重新计算（部分整线工艺能力来源于资源池基线能力）认证状态改为待提交认证（没有宣称能力认证）
     * 3.线体整线工艺实际能力变动（判断实际能力是否=宣称能力） 认证状态改为待提交认证
     */
    @Override
    public void changeLineDevice(Integer pcbaLineId, Date d, String userId) {
        List<BaseCapacityRule> baseCapacityRuleList = baseCapacityRuleDao.getAllBaseCapacityRule(null, null, null);
        List<LineBaseCapacityValue> oldLineBaseCapacityValueList = new ArrayList<>();
        List<LineBaseCapacityValue> newLineBaseCapacityValueList = new ArrayList<>();
        for (BaseCapacityRule baseCapacityRule : baseCapacityRuleList) {
            String lineBaseParamKey = baseCapacityRule.getLineBaseParamKey();
            String pcbaDeviceParamKeys = baseCapacityRule.getPcbaDeviceParamKeys();
            String pcbaDeviceParamKeys2 = baseCapacityRule.getPcbaDeviceParamKeys2();
            Integer baseCapacityRuleType = baseCapacityRule.getBaseCapacityRuleType();
            String pcbaDeviceUse = baseCapacityRule.getDeviceUse();
            /*1：取最大值
            2：取最小值
            3：取当前值
            4：取最小值[特殊，取前两位判断大小]
            5：取最大值[特殊，取前两位判断大小]
            6：取和值
            7：只要有一台为”是“，则为是；全部”否“，则为”否“
            8：只要任意一台填写”有“，则为”有“
            9：取第一个集合的最大值在和第二个集合取最小值
            */
            List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLineId);
            List<Map<String, String>> deviceResourceIdList = new ArrayList<>();
            for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                Map<String, String> map = new HashMap<>();
                map.put("deviceResourceId", (pcbaDevice.getPcbaDeviceResourceId() != null && !"".equals(pcbaDevice.getPcbaDeviceResourceId().toString())) ? pcbaDevice.getPcbaDeviceResourceId().toString() : "");
                map.put("deviceUse", (pcbaDevice.getPurpose() != null && !"".equals(pcbaDevice.getPurpose())) ? pcbaDevice.getPurpose() : "");
                deviceResourceIdList.add(map);
            }
            String fV = "";
            if ("1".equals(baseCapacityRuleType.toString())) {
                //取最大值
                String finalValue1 = "";
                String finalValue2 = "";

                // 按照 先循环 key 找出最大值
                List<String> valueList = new ArrayList<>();
                if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                    String[] keyArr = pcbaDeviceParamKeys.split(",");
                    for (String s : keyArr) {
                        //System.out.println("key：" + s);
                        // 根据pcbaDeviceResourceId 和 key 值查询当前值
                        String currentValue = "";
                        for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                        valueList.add(currentValue);
                    }
                }
                if (valueList.size() == 0) {
                    finalValue1 = "";
                } else {
                    for (String s : valueList) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue1)) {
                                finalValue1 = s;
                            } else {
                                if (Double.parseDouble(finalValue1) <= Double.parseDouble(s)) {
                                    finalValue1 = s;
                                }
                            }
                        } else {
                            if ("不限制".equals(s)) {
                                finalValue1 = "不限制";
                            }
                        }
                    }
                }

                // 按照 先循环 设备资源id 找出最大值
                List<String> valueList2 = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList2.add(currentValue);
                }
                if (valueList2.size() == 0) {
                    finalValue2 = "";
                } else {
                    for (String s : valueList2) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue2)) {
                                finalValue2 = s;
                            } else {
                                if (Double.parseDouble(finalValue2) <= Double.parseDouble(s)) {
                                    finalValue2 = s;
                                }
                            }
                        } else {
                            if ("不限制".equals(s)) {
                                finalValue1 = "不限制";
                            }
                        }
                    }
                }

                // 比较 finalValue1 和 finalValue2 取最大
                if ("不限制".equals(finalValue1)) {
                    fV = "不限制";
                } else {
                    Double finalValue_1 = 0.0;
                    Double finalValue_2 = 0.0;
                    Double finalValue = 0.0;
                    if (CommonUtils.isNumeric(finalValue1)) {
                        finalValue_1 = Double.parseDouble(finalValue1);
                    } else {
                        finalValue_1 = 0.0;
                    }
                    if (CommonUtils.isNumeric(finalValue2)) {
                        finalValue_2 = Double.parseDouble(finalValue2);
                    } else {
                        finalValue_2 = 0.0;
                    }
                    if (finalValue_1 >= finalValue_2) {
                        finalValue = finalValue_1;
                    } else {
                        finalValue = finalValue_2;
                    }

                    fV = "0.0".equals(finalValue.toString()) ? "" : CommonUtils.removeZeros(finalValue.toString());
                }
            } else if ("2".equals(baseCapacityRuleType.toString())) {
                //取最小值
                String finalValue1 = "";
                String finalValue2 = "";

                // 按照 先循环 key 找出最大值
                List<String> valueList = new ArrayList<>();
                if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                    String[] keyArr = pcbaDeviceParamKeys.split(",");
                    for (String s : keyArr) {
                        //System.out.println("key：" + s);
                        // 根据pcbaDeviceResourceId 和 key 值查询当前值
                        String currentValue = "";
                        for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                        valueList.add(currentValue);
                    }
                }
                if (valueList.size() == 0) {
                    finalValue1 = "";
                } else {
                    for (String s : valueList) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue1)) {
                                finalValue1 = s;
                            } else {
                                if (Double.parseDouble(finalValue1) >= Double.parseDouble(s)) {
                                    finalValue1 = s;
                                }
                            }
                        }
                    }
                }

                // 按照 先循环 设备资源id 找出最大值
                List<String> valueList2 = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList2.add(currentValue);
                }
                if (valueList2.size() == 0) {
                    finalValue2 = "";
                } else {
                    for (String s : valueList2) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue2)) {
                                finalValue2 = s;
                            } else {
                                if (Double.parseDouble(finalValue2) >= Double.parseDouble(s)) {
                                    finalValue2 = s;
                                }
                            }
                        }
                    }
                }

                // 比较 finalValue1 和 finalValue2 取最大
                Double finalValue_1 = 0.0;
                Double finalValue_2 = 0.0;
                Double finalValue = 0.0;
                if (CommonUtils.isNumeric(finalValue1)) {
                    finalValue_1 = Double.parseDouble(finalValue1);
                } else {
                    finalValue_1 = 0.0;
                }
                if (CommonUtils.isNumeric(finalValue2)) {
                    finalValue_2 = Double.parseDouble(finalValue2);
                } else {
                    finalValue_2 = 0.0;
                }
                if (finalValue_1 <= finalValue_2) {
                    finalValue = finalValue_1;
                } else {
                    finalValue = finalValue_2;
                }

                fV = "0.0".equals(finalValue.toString()) ? "" : CommonUtils.removeZeros(finalValue.toString());
            } else if ("3".equals(baseCapacityRuleType.toString())) {
                //取当前值
//                List<String> valueList = new ArrayList<>();
//                if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
//                    String[] keyArr = pcbaDeviceParamKeys.split(",");
//                    for (String s : keyArr) {
//                        //System.out.println("key：" + s);
//                        // 根据pcbaDeviceResourceId 和 key 值查询当前值
//                        String currentValue = "";
//                        for (Map<String, String> deviceResourceId : deviceResourceIdList) {
//                            String deviceUse = deviceResourceId.get("deviceUse");
//                            if(DeviceUseName.AOI_LUHOU.equals(deviceUse)){
//                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
//                                if(pcbaDeviceRelatedDeviceParam != null){
//                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
//                                }
//                                break;
//                            }
//                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
//                            if(pcbaDeviceRelatedDeviceParam != null){
//                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
//                                break;
//                            }
//                        }
//                        valueList.add(currentValue);
//                    }
//                }
//                String finalValue = "";
//                if(valueList.size() == 0){
//                    finalValue = "";
//                }else{
//                    finalValue = valueList.get(0);
//                }
//                fV = finalValue;
                if (DeviceUseName.AOI_LUHOU.equals(pcbaDeviceUse)) {
                    List<String> valueList = new ArrayList<>();
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        String currentValue = "";
                        for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                            String deviceUse = deviceResourceId.get("deviceUse");
                            if (DeviceUseName.AOI_LUHOU.equals(deviceUse)) {
                                String[] lineBaseParamKeys = new String[]{"input_1690168363211", "input_1690168363212", "input_1690168363213", "input_1690168363214"};
                                for (String key : lineBaseParamKeys) {
                                    if (key.equals(lineBaseParamKey)) {
                                        BaseCapacityRule baseCapacityRuleByKey = baseCapacityRuleDao.getBaseCapacityRuleByKey(key);
                                        if (baseCapacityRuleByKey != null) {
                                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(baseCapacityRuleByKey.getPcbaDeviceParamKeys(), Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                            if (pcbaDeviceRelatedDeviceParam != null) {
                                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                            }
                                            valueList.add(currentValue);
                                            break;
                                        }
                                    }

                                }
                            }
                        }

                    }
                    String finalValue = "";
                    if (valueList.size() == 0) {
                        finalValue = "";
                    } else {
                        finalValue = valueList.get(0);
                    }
                    fV = finalValue;
                } else {
                    List<String> valueList = new ArrayList<>();
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            //System.out.println("key：" + s);
                            // 根据pcbaDeviceResourceId 和 key 值查询当前值
                            String currentValue = "";
                            for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                                PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                                if (pcbaDeviceRelatedDeviceParam != null) {
                                    currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                    break;
                                }

                            }
                            valueList.add(currentValue);
                        }
                    }
                    String finalValue = "";
                    if (valueList.size() == 0) {
                        finalValue = "";
                    } else {
                        finalValue = valueList.get(0);
                    }
                    fV = finalValue;
                }
            } else if ("4".equals(baseCapacityRuleType.toString())) {
                //取当前线体中所有该设备资源当前值 前两位判定大小 【同时取最小值】
                String finalValue1 = "";
                String finalValue2 = "";

                // 按照 先循环 key 找出最大值
                List<String> valueList = new ArrayList<>();
                if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                    String[] keyArr = pcbaDeviceParamKeys.split(",");
                    for (String s : keyArr) {
                        System.out.println("key：" + s);
                        // 根据pcbaDeviceResourceId 和 key 值查询当前值
                        String currentValue = "";
                        for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                        valueList.add(currentValue);
                    }
                }
                if (valueList.size() == 0) {
                    finalValue1 = "";
                } else {
                    for (String s : valueList) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue1)) {
                                finalValue1 = s;
                            } else {
                                String ss = "";
                                if (s.length() >= 2) {
                                    ss = s.substring(0, 2);
                                    if (Double.parseDouble(ss) <= Double.parseDouble(finalValue1.substring(0, 2))) {
                                        finalValue1 = s;
                                    }
                                }
                            }
                        }
                    }
                }

                // 按照 先循环 设备资源id 找出最大值
                List<String> valueList2 = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList2.add(currentValue);
                }
                if (valueList2.size() == 0) {
                    finalValue2 = "";
                } else {
                    for (String s : valueList2) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue2)) {
                                finalValue2 = s;
                            } else {
                                String ss = "";
                                if (s.length() >= 2) {
                                    ss = s.substring(0, 2);
                                    if (Double.parseDouble(ss) <= Double.parseDouble(finalValue2.substring(0, 2))) {
                                        finalValue2 = s;
                                    }
                                }
                            }
                        }
                    }
                }

                // 比较 finalValue1 和 finalValue2 前2位 取最小
                String finalValue_1 = "";
                String finalValue_2 = "";
                String finalValue = "";
                if (finalValue1.length() >= 2 && CommonUtils.isNumeric(finalValue1.substring(0, 2))) {
                    finalValue_1 = finalValue1;
                } else {
                    finalValue_1 = "";
                }
                if (finalValue2.length() >= 2 && CommonUtils.isNumeric(finalValue2.substring(0, 2))) {
                    finalValue_2 = finalValue2;
                } else {
                    finalValue_2 = "";
                }
                if (!"".equals(finalValue_1) && !"".equals(finalValue_2)) {
                    if (Double.parseDouble(finalValue1.substring(0, 2)) <= Double.parseDouble(finalValue2.substring(0, 2))) {
                        finalValue = finalValue_1;
                    } else {
                        finalValue = finalValue_2;
                    }
                } else {
                    if ("".equals(finalValue_1)) {
                        finalValue = finalValue_2;
                    } else {
                        finalValue = finalValue_1;
                    }
                }

                fV = finalValue;
            } else if ("5".equals(baseCapacityRuleType.toString())) {
                //取当前线体中所有该设备资源当前值 前两位判定大小 【同时取最大值】
                String finalValue1 = "";
                String finalValue2 = "";

                // 按照 先循环 key 找出最大值
                List<String> valueList = new ArrayList<>();
                if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                    String[] keyArr = pcbaDeviceParamKeys.split(",");
                    for (String s : keyArr) {
                        //System.out.println("key：" + s);
                        // 根据pcbaDeviceResourceId 和 key 值查询当前值
                        String currentValue = "";
                        for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                        valueList.add(currentValue);
                    }
                }
                if (valueList.size() == 0) {
                    finalValue1 = "";
                } else {
                    for (String s : valueList) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue1)) {
                                finalValue1 = s;
                            } else {
                                String ss = "";
                                if (s.length() >= 2) {
                                    ss = s.substring(0, 2);
                                    if (Double.parseDouble(ss) >= Double.parseDouble(finalValue1.substring(0, 2))) {
                                        finalValue1 = s;
                                    }
                                }
                            }
                        }
                    }
                }

                // 按照 先循环 设备资源id 找出最大值
                List<String> valueList2 = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList2.add(currentValue);
                }
                if (valueList2.size() == 0) {
                    finalValue2 = "";
                } else {
                    for (String s : valueList2) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue2)) {
                                finalValue2 = s;
                            } else {
                                String ss = "";
                                if (s.length() >= 2) {
                                    ss = s.substring(0, 2);
                                    if (Double.parseDouble(ss) >= Double.parseDouble(finalValue2.substring(0, 2))) {
                                        finalValue2 = s;
                                    }
                                }
                            }
                        }
                    }
                }

                // 比较 finalValue1 和 finalValue2 前2位 取最大
                String finalValue_1 = "";
                String finalValue_2 = "";
                String finalValue = "";
                if (finalValue1.length() >= 2 && CommonUtils.isNumeric(finalValue1.substring(0, 2))) {
                    finalValue_1 = finalValue1;
                } else {
                    finalValue_1 = "";
                }
                if (finalValue2.length() >= 2 && CommonUtils.isNumeric(finalValue2.substring(0, 2))) {
                    finalValue_2 = finalValue2;
                } else {
                    finalValue_2 = "";
                }
                if (!"".equals(finalValue_1) && !"".equals(finalValue_2)) {
                    if (Double.parseDouble(finalValue1.substring(0, 2)) >= Double.parseDouble(finalValue2.substring(0, 2))) {
                        finalValue = finalValue_1;
                    } else {
                        finalValue = finalValue_2;
                    }
                } else {
                    if ("".equals(finalValue_1)) {
                        finalValue = finalValue_2;
                    } else {
                        finalValue = finalValue_1;
                    }
                }

                fV = finalValue;
            } else if ("6".equals(baseCapacityRuleType.toString())) {
                // 按照设备资源循环 求 值的和
                // 取和值
                List<String> valueList = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList.add(currentValue);
                }
                String finalValue = "";
                Double finalValueDouble = 0.0;
                if (valueList.size() == 0) {
                    finalValue = "";
                } else {
                    for (String s : valueList) {
                        // 取和
                        if (CommonUtils.isNumeric(s)) {
                            finalValueDouble = finalValueDouble + Double.parseDouble(s);
                        }
                    }
                    if (finalValueDouble > 0) {
                        finalValue = CommonUtils.removeZeros(finalValueDouble.toString());
                    }
                }

                fV = finalValue;
            } else if ("7".equals(baseCapacityRuleType.toString())) {
                // 只要有一台为”是“，则为是；全部”否“，则为”否“
                List<String> valueList1 = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList1.add(currentValue);
                }

                List<String> valueList2 = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList2.add(currentValue);
                }

                String finalValue = "";
                if (valueList1.contains("是") || valueList2.contains("是")) {
                    finalValue = "是";
                } else {
                    finalValue = "否";
                }

                fV = finalValue;
            } else if ("8".equals(baseCapacityRuleType.toString())) {
                // 只要任意一台填写”有“，则为”有“
                List<String> valueList1 = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList1.add(currentValue);
                }

                List<String> valueList2 = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList2.add(currentValue);
                }

                String finalValue = "";
                if (valueList1.contains("有") || valueList2.contains("有")) {
                    finalValue = "有";
                } else {
                    finalValue = "";
                }

                fV = finalValue;
            } else if ("9".equals(baseCapacityRuleType.toString())) {
                // 取第一个集合的最大值在和第二个集合取最小值
                // 第一个集合取最大值 pcbaDeviceParamKeys2
                String finalValue1_ = "";
                String finalValue2_ = "";

                // 按照 先循环 key 找出最大值
                List<String> valueList_ = new ArrayList<>();
                if (pcbaDeviceParamKeys2 != null && !"".equals(pcbaDeviceParamKeys2)) {
                    String[] keyArr = pcbaDeviceParamKeys2.split(",");
                    for (String s : keyArr) {
                        //System.out.println("key：" + s);
                        // 根据pcbaDeviceResourceId 和 key 值查询当前值
                        String currentValue = "";
                        for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                        valueList_.add(currentValue);
                    }
                }
                if (valueList_.size() == 0) {
                    finalValue1_ = "";
                } else {
                    for (String s : valueList_) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue1_)) {
                                finalValue1_ = s;
                            } else {
                                if (Double.parseDouble(finalValue1_) <= Double.parseDouble(s)) {
                                    finalValue1_ = s;
                                }
                            }
                        }
                    }
                }

                // 按照 先循环 设备资源id 找出最大值
                List<String> valueList2_ = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys2 != null && !"".equals(pcbaDeviceParamKeys2)) {
                        String[] keyArr = pcbaDeviceParamKeys2.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList2_.add(currentValue);
                }
                if (valueList2_.size() == 0) {
                    finalValue2_ = "";
                } else {
                    for (String s : valueList2_) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue2_)) {
                                finalValue2_ = s;
                            } else {
                                if (Double.parseDouble(finalValue2_) <= Double.parseDouble(s)) {
                                    finalValue2_ = s;
                                }
                            }
                        }
                    }
                }

                // 比较 finalValue1 和 finalValue2 取最大
                Double finalValue_1_ = 0.0;
                Double finalValue_2_ = 0.0;
                Double finalValue_ = 0.0;
                if (CommonUtils.isNumeric(finalValue1_)) {
                    finalValue_1_ = Double.parseDouble(finalValue1_);
                } else {
                    finalValue_1_ = 0.0;
                }
                if (CommonUtils.isNumeric(finalValue2_)) {
                    finalValue_2_ = Double.parseDouble(finalValue2_);
                } else {
                    finalValue_2_ = 0.0;
                }
                if (finalValue_1_ >= finalValue_2_) {
                    finalValue_ = finalValue_1_;
                } else {
                    finalValue_ = finalValue_2_;
                }


                // 再取最小值
                String finalValue1 = "";
                String finalValue2 = "";

                // 按照 先循环 key 找出最大值
                List<String> valueList = new ArrayList<>();
                if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                    String[] keyArr = pcbaDeviceParamKeys.split(",");
                    for (String s : keyArr) {
                        //System.out.println("key：" + s);
                        // 根据pcbaDeviceResourceId 和 key 值查询当前值
                        String currentValue = "";
                        for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                        valueList.add(currentValue);
                    }
                }
                if (valueList.size() == 0) {
                    finalValue1 = "";
                } else {
                    for (String s : valueList) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue1)) {
                                finalValue1 = s;
                            } else {
                                if (Double.parseDouble(finalValue1) >= Double.parseDouble(s)) {
                                    finalValue1 = s;
                                }
                            }
                        }
                    }
                }

                // 按照 先循环 设备资源id 找出最大值
                List<String> valueList2 = new ArrayList<>();
                for (Map<String, String> deviceResourceId : deviceResourceIdList) {
                    String currentValue = "";
                    if (pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)) {
                        String[] keyArr = pcbaDeviceParamKeys.split(",");
                        for (String s : keyArr) {
                            PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, Integer.parseInt(deviceResourceId.get("deviceResourceId")));
                            if (pcbaDeviceRelatedDeviceParam != null) {
                                currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                break;
                            }
                        }
                    }
                    valueList2.add(currentValue);
                }
                if (valueList2.size() == 0) {
                    finalValue2 = "";
                } else {
                    for (String s : valueList2) {
                        // 取最大值
                        // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                        if (CommonUtils.isNumeric(s)) {
                            if ("".equals(finalValue2)) {
                                finalValue2 = s;
                            } else {
                                if (Double.parseDouble(finalValue2) >= Double.parseDouble(s)) {
                                    finalValue2 = s;
                                }
                            }
                        }
                    }
                }

                // 比较 finalValue1 和 finalValue2 取最大
                Double finalValue_1 = 0.0;
                Double finalValue_2 = 0.0;
                Double finalValue = 0.0;
                if (CommonUtils.isNumeric(finalValue1)) {
                    finalValue_1 = Double.parseDouble(finalValue1);
                } else {
                    finalValue_1 = 0.0;
                }
                if (CommonUtils.isNumeric(finalValue2)) {
                    finalValue_2 = Double.parseDouble(finalValue2);
                } else {
                    finalValue_2 = 0.0;
                }
                if (finalValue_1 <= finalValue_2) {
                    finalValue = finalValue_1;
                } else {
                    finalValue = finalValue_2;
                }

                // 将 finalValue_ 和 finalValue 取最小值
                if (finalValue_ < finalValue) {
                    finalValue = finalValue_;
                }

                fV = "0.0".equals(finalValue.toString()) ? "" : CommonUtils.removeZeros(finalValue.toString());
            } else {
                fV = "NA";
            }

            LineBaseCapacityValue oldLineBaseCapacityValue = lineBaseCapacityValueDao.getLineBaseCapacityValueByKeyAndLineId(pcbaLineId, lineBaseParamKey);
            if (oldLineBaseCapacityValue != null) {
                String lineBaseCapacityParamValue = oldLineBaseCapacityValue.getLineBaseCapacityParamValue();
                Integer lineBaseCapacityValueId = oldLineBaseCapacityValue.getLineBaseCapacityValueId();
                if (!lineBaseCapacityParamValue.equals(fV)) {
                    oldLineBaseCapacityValueList.add(oldLineBaseCapacityValue);
                    // update
                    LineBaseCapacityValue updateLineBaseCapacityValue = new LineBaseCapacityValue();
                    updateLineBaseCapacityValue.setLineBaseCapacityValueId(lineBaseCapacityValueId);
                    updateLineBaseCapacityValue.setUpdateTime(d);
                    updateLineBaseCapacityValue.setLineBaseCapacityParamValue(fV);
                    lineBaseCapacityValueDao.updateLineBaseCapacityValue(updateLineBaseCapacityValue);
                    newLineBaseCapacityValueList.add(updateLineBaseCapacityValue);
                }
            }
        }
        if (oldLineBaseCapacityValueList.size() > 0) {
            // 操作日志
            operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 3, new Date(), JSONObject.toJSONString(oldLineBaseCapacityValueList), JSONObject.toJSONString(newLineBaseCapacityValueList)));
        }
        changeLineBaseCapacityValue(pcbaLineId, d, userId);
    }

    /**
     * 改变线体整线基线能力值
     * 1.线体整线工艺宣称能力重新计算（部分整线工艺能力来源于资源池基线能力）认证状态改为待提交认证[没有宣称能力认证]
     * 2.线体整线工艺实际能力变动（判断实际能力是否=宣称能力） 认证状态改为待提交认证
     */
    @Override
    public void changeLineBaseCapacityValue(Integer pcbaLineId, Date d, String userId) {
        List<LineBaseCapacityValue> lineBaseCapacityValueList = lineBaseCapacityValueDao.getAllLineBaseCapacityValueByLineId(pcbaLineId);
        List<LineTechCapacityValue> oldLineTechCapacityValueList = new ArrayList<>();
        List<LineTechCapacityValue> newLineTechCapacityValueList = new ArrayList<>();
        for (LineBaseCapacityValue lineBaseCapacityValue : lineBaseCapacityValueList) {
            String lineBaseCapacityParamKey = lineBaseCapacityValue.getLineBaseCapacityParamKey();
            String lineBaseCapacityParamValue = lineBaseCapacityValue.getLineBaseCapacityParamValue();
            List<TechCapacityRule> techCapacityRuleList = techCapacityRuleDao.getAllTechCapacityRule(null, null, null);
            for (TechCapacityRule techCapacityRule : techCapacityRuleList) {
                String baseCapacityParamKey = techCapacityRule.getBaseCapacityParamKey();
                String lineTechParamKey = techCapacityRule.getLineTechParamKey();
                Integer techCapacityRuleType = techCapacityRule.getTechCapacityRuleType();
                String declareValue = techCapacityRule.getDeclareValue();
                Integer actualEqualDeclare = techCapacityRule.getActualEqualDeclare();
                if (baseCapacityParamKey != null && baseCapacityParamKey.equals(lineBaseCapacityParamKey)) {
                    /*1:来自于基线对应值
                    2：手动填
                    */
                    if (techCapacityRuleType == 1) {
                        if (!lineBaseCapacityParamValue.equals(declareValue)) {
                            // update
                            LineTechCapacityValue oldLineTechCapacityValue = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(pcbaLineId, lineTechParamKey);
                            if (oldLineTechCapacityValue != null) {
                                oldLineTechCapacityValueList.add(oldLineTechCapacityValue);
                                Integer lineTechCapacityValueId = oldLineTechCapacityValue.getLineTechCapacityValueId();
                                LineTechCapacityValue updateLineTechCapacityValue = new LineTechCapacityValue();
                                updateLineTechCapacityValue.setLineTechCapacityValueId(lineTechCapacityValueId);
                                if (actualEqualDeclare != null && actualEqualDeclare == 1) {
                                    updateLineTechCapacityValue.setLineTechCapacityParamValueActual(lineBaseCapacityParamValue);
                                }
                                updateLineTechCapacityValue.setLineTechCapacityParamValue(lineBaseCapacityParamValue);
                                updateLineTechCapacityValue.setUpdateTime(d);
                                lineTechCapacityValueDao.updateLineTechCapacityValue(updateLineTechCapacityValue);
                                newLineTechCapacityValueList.add(updateLineTechCapacityValue);

                                PcbaLine oldPcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
                                PcbaLine updatePcbaLine = new PcbaLine();
                                updatePcbaLine.setPcbaLineId(pcbaLineId);
                                updatePcbaLine.setParamsStatusDeclare(1);
                                if (actualEqualDeclare != null && actualEqualDeclare == 1) {
                                    updatePcbaLine.setParamsStatusActual(4);
                                }
                                pcbaLineDao.updatePcbaLine(updatePcbaLine);
                                // 操作日志
                                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 3, new Date(), JSONObject.toJSONString(oldPcbaLine), JSONObject.toJSONString(updatePcbaLine)));
                            }
                        }
                    }
                }
            }
        }
        // 操作日志
        operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 3, new Date(), JSONObject.toJSONString(oldLineTechCapacityValueList), JSONObject.toJSONString(newLineTechCapacityValueList)));
    }

    /**
     * 改变线体整线工艺宣称能力
     * 1.线体整线工艺实际能力变动（判断实际能力是否=宣称能力） 认证状态改为待提交认证
     */
    @Override
    public void changeLineTechCapacityDeclareValue(Integer pcbaLineId, Date d, String userId) {
        List<LineTechCapacityValue> lineTechCapacityValueList = lineTechCapacityValueDao.getAllLineTechCapacityValueByLineId(pcbaLineId);
        List<LineTechCapacityValue> oldLineTechCapacityValueList = new ArrayList<>();
        List<LineTechCapacityValue> newLineTechCapacityValueList = new ArrayList<>();
        for (LineTechCapacityValue lineTechCapacityValue : lineTechCapacityValueList) {
            String lineTechCapacityParamKey = lineTechCapacityValue.getLineTechCapacityParamKey();
            String lineTechCapacityParamValue = lineTechCapacityValue.getLineTechCapacityParamValue();
            String lineTechCapacityParamValueActual = lineTechCapacityValue.getLineTechCapacityParamValueActual();
            TechCapacityRule techCapacityRuleByKey = techCapacityRuleDao.getTechCapacityRuleByKey(lineTechCapacityParamKey);
            if (techCapacityRuleByKey != null) {
                Integer actualEqualDeclare = techCapacityRuleByKey.getActualEqualDeclare();
                if (actualEqualDeclare != null && actualEqualDeclare == 1) {
                    if (!lineTechCapacityParamValue.equals(lineTechCapacityParamValueActual)) {
                        LineTechCapacityValue oldLineTechCapacityValue = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(pcbaLineId, lineTechCapacityParamKey);
                        if (oldLineTechCapacityValue != null) {
                            oldLineTechCapacityValueList.add(oldLineTechCapacityValue);
                            Integer lineTechCapacityValueId = oldLineTechCapacityValue.getLineTechCapacityValueId();
                            // update
                            LineTechCapacityValue updateLineTechCapacityValue = new LineTechCapacityValue();
                            updateLineTechCapacityValue.setUpdateTime(d);
                            updateLineTechCapacityValue.setLineTechCapacityValueId(lineTechCapacityValueId);
                            updateLineTechCapacityValue.setLineTechCapacityParamValueActual(lineTechCapacityParamValue);
                            lineTechCapacityValueDao.updateLineTechCapacityValue(updateLineTechCapacityValue);
                            newLineTechCapacityValueList.add(updateLineTechCapacityValue);

                            PcbaLine oldPcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
                            PcbaLine updatePcbaLine = new PcbaLine();
                            updatePcbaLine.setPcbaLineId(pcbaLineId);
                            updatePcbaLine.setUpdateTime(d);
                            updatePcbaLine.setParamsStatusActual(4);
                            pcbaLineDao.updatePcbaLine(updatePcbaLine);

                            // 操作日志
                            operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 3, new Date(), JSONObject.toJSONString(oldPcbaLine), JSONObject.toJSONString(updatePcbaLine)));
                        }
                    }
                }
            }
        }
        // 操作日志
        operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 3, new Date(), JSONObject.toJSONString(oldLineTechCapacityValueList), JSONObject.toJSONString(newLineTechCapacityValueList)));
    }

    /**
     * 即时刷新pcba能力匹配
     * 1.基线参数 is_related_pcba 值发生变化   type = 1
     * 2.工艺参数 is_related_pcba 值发生变化   type = 2
     * 3.整线能力 is_related_pcba 值发生变化   type = 3
     * 4.设备备注发生变化                      type = 4
     */
    @Override
    public void changePcbaCapacity(Integer type, String beforeStr, String afterStr, Integer pcbaDeviceTypeId, Integer pcbaDeviceId, Integer pcbaLineId) {
        try {
            if (type == 1) {
                List<PcbaDeviceParam> allPcbaDeviceParam = pcbaDeviceParamDao.getAllPcbaDeviceParam(pcbaDeviceTypeId, null, null);
                List<PcbaDeviceParam> allPcbaDeviceParamRelatedPcba = new ArrayList<>();
                for (PcbaDeviceParam pcbaDeviceParam : allPcbaDeviceParam) {
                    if (pcbaDeviceParam.getIsRelatedPcba() == 1) {
                        allPcbaDeviceParamRelatedPcba.add(pcbaDeviceParam);
                    }
                }
                // 逻辑待完善

            } else if (type == 2) {

            } else if (type == 3) {

            } else if (type == 4) {
                if (!beforeStr.equals(afterStr)) {
                    this.refreshPcbaTouchan();
                }
            } else {
                this.refreshPcbaTouchan();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void updatePcbaLineFinalStatus(Integer type, List<PcbaLine> pcbaLineList) {
        List<Integer> pcbaLineIdList = new ArrayList<>();
        if (type == 1) {
            pcbaLineList = pcbaLineDao.getAllPcbaLine(null, null, null, null, null, null, null, null, null, null, null);
            for (PcbaLine pcbaLine : pcbaLineList) {
                if (pcbaLine.getPcbaLineType() == 1) {
                    // SMT线体
                    if (pcbaLine.getStatus() != null && pcbaLine.getStatus() == 1 &&
                            pcbaLine.getParamsStatusBase() != null && pcbaLine.getParamsStatusBase() == 1 &&
                            pcbaLine.getParamsStatusDeclare() != null && pcbaLine.getParamsStatusDeclare() == 1 &&
                            pcbaLine.getParamsStatusActual() != null && pcbaLine.getParamsStatusActual() == 1 &&
                            pcbaLine.getLockDeclare() != null && pcbaLine.getLockDeclare() == 1
                    ) {
                        List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                        boolean flag = true;
                        for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                            PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                            if (pcbaDeviceResource.getAuditStatusBase() == null || pcbaDeviceResource.getAuditStatusBase() != 1 || pcbaDeviceResource.getAuditStatusTech() == null || pcbaDeviceResource.getAuditStatusTech() != 1 || pcbaDevice.getParamsStatus() == null || pcbaDevice.getParamsStatus() != 1) {
                                flag = false;
                                break;
                            }
                        }
                        if (flag) {
                            pcbaLineIdList.add(pcbaLine.getPcbaLineId());
                        }
                    }
                } else {
                    // 离线非SMT线体
                    if (pcbaLine.getStatus() != null && pcbaLine.getStatus() == 1 &&
                            pcbaLine.getParamsStatusBase() != null && pcbaLine.getParamsStatusBase() == 1
                    ) {
                        List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                        boolean flag = true;
                        for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                            PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                            if (pcbaDeviceResource.getAuditStatusBase() == null || pcbaDeviceResource.getAuditStatusBase() != 1 || pcbaDeviceResource.getAuditStatusTech() == null || pcbaDeviceResource.getAuditStatusTech() != 1 || pcbaDevice.getParamsStatus() == null || pcbaDevice.getParamsStatus() != 1) {
                                flag = false;
                                break;
                            }
                        }
                        if (flag) {
                            pcbaLineIdList.add(pcbaLine.getPcbaLineId());
                        }
                    }
                }
                for (PcbaLine line : pcbaLineList) {
                    if (pcbaLineIdList.contains(line.getPcbaLineId())) {
                        pcbaLineDao.updatePcbaLineFinalStatus(line.getPcbaLineId(), 1);
                    } else {
                        pcbaLineDao.updatePcbaLineFinalStatus(line.getPcbaLineId(), 2);
                    }
                }
            }
        } else {
            for (PcbaLine pcbaLine : pcbaLineList) {
                if (pcbaLine.getPcbaLineType() == 1) {
                    // SMT线体
                    if (pcbaLine.getStatus() != null && pcbaLine.getStatus() == 1 &&
                            pcbaLine.getParamsStatusBase() != null && pcbaLine.getParamsStatusBase() == 1 &&
                            pcbaLine.getParamsStatusDeclare() != null && pcbaLine.getParamsStatusDeclare() == 1 &&
                            pcbaLine.getParamsStatusActual() != null && pcbaLine.getParamsStatusActual() == 1 &&
                            pcbaLine.getLockDeclare() != null && pcbaLine.getLockDeclare() == 1
                    ) {
                        List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                        boolean flag = true;
                        for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                            PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                            if (pcbaDeviceResource.getAuditStatusBase() == null || pcbaDeviceResource.getAuditStatusBase() != 1 || pcbaDeviceResource.getAuditStatusTech() == null || pcbaDeviceResource.getAuditStatusTech() != 1 || pcbaDevice.getParamsStatus() == null || pcbaDevice.getParamsStatus() != 1) {
                                flag = false;
                                break;
                            }
                        }
                        if (flag) {
                            pcbaLineIdList.add(pcbaLine.getPcbaLineId());
                        }
                    }
                } else {
                    // 离线非SMT线体
                    if (pcbaLine.getStatus() != null && pcbaLine.getStatus() == 1 &&
                            pcbaLine.getParamsStatusBase() != null && pcbaLine.getParamsStatusBase() == 1
                    ) {
                        List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                        boolean flag = true;
                        for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                            PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                            if (pcbaDeviceResource.getAuditStatusBase() == null || pcbaDeviceResource.getAuditStatusBase() != 1 || pcbaDeviceResource.getAuditStatusTech() == null || pcbaDeviceResource.getAuditStatusTech() != 1 || pcbaDevice.getParamsStatus() == null || pcbaDevice.getParamsStatus() != 1) {
                                flag = false;
                                break;
                            }
                        }
                        if (flag) {
                            pcbaLineIdList.add(pcbaLine.getPcbaLineId());
                        }
                    }
                }
                for (PcbaLine line : pcbaLineList) {
                    if (pcbaLineIdList.contains(line.getPcbaLineId())) {
                        pcbaLineDao.updatePcbaLineFinalStatus(line.getPcbaLineId(), 1);
                    } else {
                        pcbaLineDao.updatePcbaLineFinalStatus(line.getPcbaLineId(), 2);
                    }
                }
            }
        }
    }

    @Override
    public void cascadeUpdateLineFinalStatus(Integer type, Integer pcbaDeviceResourceId, Integer pcbaDeviceId, Integer pcbaLineId) {
        List<PcbaLine> pcbaLineList = new ArrayList<>();
        if (type == 1) {
            // 资源池维度
            if (pcbaDeviceResourceId != null) {
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceResourceByPcbaDeviceResourceId(pcbaDeviceResourceId);
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    PcbaLine line = pcbaLineDao.getPcbaLineById(pcbaDevice.getPcbaLineId());
                    if (line != null) {
                        if (!pcbaLineList.contains(line)) {
                            pcbaLineList.add(line);
                        }
                    }
                }
            }
        } else if (type == 2) {
            // 设备维度
            if (pcbaDeviceId != null) {
                PcbaDevice pcbaDevice = pcbaDeviceDao.getById(pcbaDeviceId);
                if (pcbaDevice != null) {
                    Integer lineId = pcbaDevice.getPcbaLineId();
                    if (lineId != null) {
                        PcbaLine line = pcbaLineDao.getPcbaLineById(lineId);
                        if (line != null) {
                            if (!pcbaLineList.contains(line)) {
                                pcbaLineList.add(line);
                            }
                        }
                    }
                }
            }
        } else if (type == 3) {
            // 线体维度
            if (pcbaLineId != null) {
                PcbaLine line = pcbaLineDao.getPcbaLineById(pcbaLineId);
                if (line != null) {
                    if (!pcbaLineList.contains(line)) {
                        pcbaLineList.add(line);
                    }
                }
            }
        }
        if (pcbaLineList.size() > 0) {
            updatePcbaLineFinalStatus(2, pcbaLineList);
        }
    }

    void refreshPcbaTouchan() throws Exception {
//        String md5Sign = CommonUtils.encryptToMD5(CommonUtils.encryptToMD5(sign));
//        MultipartEntityBuilder params = MultipartEntityBuilder.create();
//        params.addTextBody("signature", md5Sign);
//        System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
//        System.out.println("refreshTouChanPingGuApi:请求参数" + params.toString());
//        String res = HttpUtil.sendPostFormData(refreshTouChanPingGuApi, params);
//        System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
//        System.out.println("refreshTouChanPingGuApi:返回结果" + res);
//        JSONObject jo = JSONObject.parseObject(res);
//        if("200".equals(jo.getString("code"))){
//            System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
//            System.out.println("refreshTouChanExcelApi:请求参数" + params.toString());
//            String res2 = HttpUtil.sendPostFormData(refreshTouChanExcelApi, params);
//            System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
//            System.out.println("refreshTouChanExcelApi:返回结果" + res2);
//        }
    }

    /**
     * 修改设备工艺能力宣称值
     *//*
    public void changeDeviceDeclareCapacityAndStatus(Integer techDeviceParamFillType,
                                                     String bindDeviceParamKey,
                                                     Date d,
                                                     Integer actualEqualDeclare,
                                                     String techDeviceParamKey,
                                                     PcbaDeviceResource pcbaDeviceResource
    ){
        *//*4：来源基线
        5：取多个基线最小值*//*
        PcbaDeviceRelatedTechParam pcbaDeviceRelatedTechParam = pcbaDeviceRelatedTechParamDao.getPcbaDeviceRelatedTechParamByKeyAndDeviceResourceId(techDeviceParamKey, pcbaDeviceResource.getPcbaDeviceResourceId());
        if(techDeviceParamFillType == 4){
            if(!"".equals(bindDeviceParamKey)){
                String[] keyArr = bindDeviceParamKey.split(",");
                for (String key : keyArr) {
                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(key, pcbaDeviceResource.getPcbaDeviceResourceId());
                    if(pcbaDeviceRelatedDeviceParam != null && pcbaDeviceRelatedTechParam != null){
                        if(!pcbaDeviceRelatedTechParam.getTechDeviceParamValue().equals(pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue())){
                            PcbaDeviceRelatedTechParam updatePcbaDeviceRelatedTechParam = new PcbaDeviceRelatedTechParam();
                            updatePcbaDeviceRelatedTechParam.setPcbaDeviceRelatedTechParamId(pcbaDeviceRelatedTechParam.getPcbaDeviceRelatedTechParamId());
                            updatePcbaDeviceRelatedTechParam.setTechDeviceParamValue(pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue());
                            updatePcbaDeviceRelatedTechParam.setUpdateTime(d);
                            pcbaDeviceRelatedTechParamDao.updateDeviceRelatedParam(updatePcbaDeviceRelatedTechParam);

                            changeDeviceActualCapacityAndStatus(actualEqualDeclare,
                                    d,
                                    pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue(),
                                    techDeviceParamKey
                            );
                        }
                    }
                }
            }
        }else if(techDeviceParamFillType == 5){
            if(!"".equals(bindDeviceParamKey)){
                String[] keyArr = bindDeviceParamKey.split(",");
                List<String> valueList = new ArrayList<>();
                String finalValue = "";
                for (String key : keyArr) {
                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(key, pcbaDeviceResource.getPcbaDeviceResourceId());
                    if(pcbaDeviceRelatedDeviceParam != null && pcbaDeviceRelatedTechParam != null){
                        valueList.add(pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue());
                    }
                }
                //取最小值
                for (String s : valueList) {
                    if(CommonUtils.isNumeric(s)){
                        if("".equals(finalValue)){
                            finalValue = s;
                        }else{
                            if(Double.parseDouble(finalValue) >= Double.parseDouble(s)){
                                finalValue = s;
                            }
                        }
                    }
                }
                if(pcbaDeviceRelatedTechParam != null){
                    if(!pcbaDeviceRelatedTechParam.getTechDeviceParamValue().equals(finalValue)){
                        PcbaDeviceRelatedTechParam updatePcbaDeviceRelatedTechParam = new PcbaDeviceRelatedTechParam();
                        updatePcbaDeviceRelatedTechParam.setPcbaDeviceRelatedTechParamId(pcbaDeviceRelatedTechParam.getPcbaDeviceRelatedTechParamId());
                        updatePcbaDeviceRelatedTechParam.setTechDeviceParamValue(finalValue);
                        updatePcbaDeviceRelatedTechParam.setUpdateTime(d);
                        pcbaDeviceRelatedTechParamDao.updateDeviceRelatedParam(updatePcbaDeviceRelatedTechParam);

                        changeDeviceActualCapacityAndStatus(actualEqualDeclare,
                                d,
                                finalValue,
                                techDeviceParamKey
                        );
                    }
                }
            }
        }
    }

    *//**
     * 修改设备的实际能力值及认证状态
     *//*
    public void changeDeviceActualCapacityAndStatus(Integer actualEqualDeclare,
                                                           Date d,
                                                           String finalValue,
                                                           String techDeviceParamKey
    ){
        // 判断实际工艺能力和宣称工艺能力之间的关系
        if(actualEqualDeclare != null && actualEqualDeclare == 1){
            List<PcbaDeviceRelatedTechParamActual> pcbaDeviceRelatedTechParamActualList = pcbaDeviceRelatedTechParamActualDao.getPcbaDeviceRelatedTechParamActualByKey(techDeviceParamKey);
            for (PcbaDeviceRelatedTechParamActual pcbaDeviceRelatedTechParamActual : pcbaDeviceRelatedTechParamActualList) {
                if(!pcbaDeviceRelatedTechParamActual.getTechDeviceParamValue().equals(finalValue)){
                    PcbaDeviceRelatedTechParamActual updatePcbaDeviceRelatedTechParamActual = new PcbaDeviceRelatedTechParamActual();
                    updatePcbaDeviceRelatedTechParamActual.setUpdateTime(d);
                    updatePcbaDeviceRelatedTechParamActual.setTechDeviceParamValue(finalValue);
                    updatePcbaDeviceRelatedTechParamActual.setPcbaDeviceRelatedTechParamActualId(pcbaDeviceRelatedTechParamActual.getPcbaDeviceRelatedTechParamActualId());
                    pcbaDeviceRelatedTechParamActualDao.updateDeviceRelatedParamActual(updatePcbaDeviceRelatedTechParamActual);

                    // 将设备实际工艺能力认证状态改为 未提交认证
                    Integer pcbaDeviceId = pcbaDeviceRelatedTechParamActual.getPcbaDeviceId();
                    PcbaDevice updatePcbaDevice = new PcbaDevice();
                    updatePcbaDevice.setUpdateTime(d);
                    updatePcbaDevice.setPcbaDeviceId(pcbaDeviceId);
                    updatePcbaDevice.setParamsStatus(4);
                    pcbaDeviceDao.updatePcbaDevice(updatePcbaDevice);
                }
            }
        }
    }

    *//**
     * 修改线体的整线基线能力
     *//*
    public void changePcbaLineBaseCapacity(List<PcbaLine> pcbaLineList,
                                           List<BaseCapacityRule> baseCapacityRuleList,
                                           Date d
   ){
        for (PcbaLine pcbaLine : pcbaLineList) {
            for (BaseCapacityRule baseCapacityRule : baseCapacityRuleList) {
                Integer baseCapacityRuleType = baseCapacityRule.getBaseCapacityRuleType();
                String pcbaDeviceParamKeys = baseCapacityRule.getPcbaDeviceParamKeys();
                String lineBaseParamKey = baseCapacityRule.getLineBaseParamKey();
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                List<Integer> deviceResourceIdList = new ArrayList<>();
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    deviceResourceIdList.add(pcbaDevice.getPcbaDeviceResourceId());
                }
                String finalNewV = "";
                if(baseCapacityRuleType != null && !"".equals(baseCapacityRuleType.toString())){
                    if("1".equals(baseCapacityRuleType.toString())){
                        //取最大值
                        String finalValue1 = "";
                        String finalValue2 = "";

                        // 按照 先循环 key 找出最大值
                        List<String> valueList = new ArrayList<>();
                        if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                            for (String s : keyArr) {
                                //System.out.println("key：" + s);
                                // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                String currentValue = "";
                                for (Integer deviceResourceId : deviceResourceIdList) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                                valueList.add(currentValue);
                            }
                        }
                        if(valueList.size() == 0){
                            finalValue1 = "";
                        }else{
                            for (String s : valueList) {
                                // 取最大值
                                // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                if(CommonUtils.isNumeric(s)){
                                    if("".equals(finalValue1)){
                                        finalValue1 = s;
                                    }else{
                                        if(Double.parseDouble(finalValue1) <= Double.parseDouble(s)){
                                            finalValue1 = s;
                                        }
                                    }
                                }
                            }
                        }

                        // 按照 先循环 设备资源id 找出最大值
                        List<String> valueList2 = new ArrayList<>();
                        for (Integer deviceResourceId : deviceResourceIdList) {
                            String currentValue = "";
                            if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                            }
                            valueList2.add(currentValue);
                        }
                        if(valueList2.size() == 0){
                            finalValue2 = "";
                        }else{
                            for (String s : valueList2) {
                                // 取最大值
                                // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                if(CommonUtils.isNumeric(s)){
                                    if("".equals(finalValue2)){
                                        finalValue2 = s;
                                    }else{
                                        if(Double.parseDouble(finalValue2) <= Double.parseDouble(s)){
                                            finalValue2 = s;
                                        }
                                    }
                                }
                            }
                        }

                        // 比较 finalValue1 和 finalValue2 取最大
                        Double finalValue_1 = 0.0;
                        Double finalValue_2 = 0.0;
                        Double finalValue = 0.0;
                        if(CommonUtils.isNumeric(finalValue1)){
                            finalValue_1 = Double.parseDouble(finalValue1);
                        }else{
                            finalValue_1 = 0.0;
                        }
                        if(CommonUtils.isNumeric(finalValue2)){
                            finalValue_2 = Double.parseDouble(finalValue2);
                        }else{
                            finalValue_2 = 0.0;
                        }
                        if(finalValue_1 >= finalValue_2){
                            finalValue = finalValue_1;
                        }else{
                            finalValue = finalValue_2;
                        }
                        finalNewV = "0.0".equals(finalValue.toString()) ? "" : CommonUtils.removeZeros(finalValue.toString());
                    }else if("2".equals(baseCapacityRuleType.toString())){
                        //取最小值
                        String finalValue1 = "";
                        String finalValue2 = "";

                        // 按照 先循环 key 找出最大值
                        List<String> valueList = new ArrayList<>();
                        if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                            for (String s : keyArr) {
                                //System.out.println("key：" + s);
                                // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                String currentValue = "";
                                for (Integer deviceResourceId : deviceResourceIdList) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                                valueList.add(currentValue);
                            }
                        }
                        if(valueList.size() == 0){
                            finalValue1 = "";
                        }else{
                            for (String s : valueList) {
                                // 取最大值
                                // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                if(CommonUtils.isNumeric(s)){
                                    if("".equals(finalValue1)){
                                        finalValue1 = s;
                                    }else{
                                        if(Double.parseDouble(finalValue1) >= Double.parseDouble(s)){
                                            finalValue1 = s;
                                        }
                                    }
                                }
                            }
                        }

                        // 按照 先循环 设备资源id 找出最大值
                        List<String> valueList2 = new ArrayList<>();
                        for (Integer deviceResourceId : deviceResourceIdList) {
                            String currentValue = "";
                            if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                            }
                            valueList2.add(currentValue);
                        }
                        if(valueList2.size() == 0){
                            finalValue2 = "";
                        }else{
                            for (String s : valueList2) {
                                // 取最大值
                                // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                if(CommonUtils.isNumeric(s)){
                                    if("".equals(finalValue2)){
                                        finalValue2 = s;
                                    }else{
                                        if(Double.parseDouble(finalValue2) >= Double.parseDouble(s)){
                                            finalValue2 = s;
                                        }
                                    }
                                }
                            }
                        }

                        // 比较 finalValue1 和 finalValue2 取最大
                        Double finalValue_1 = 0.0;
                        Double finalValue_2 = 0.0;
                        Double finalValue = 0.0;
                        if(CommonUtils.isNumeric(finalValue1)){
                            finalValue_1 = Double.parseDouble(finalValue1);
                        }else{
                            finalValue_1 = 0.0;
                        }
                        if(CommonUtils.isNumeric(finalValue2)){
                            finalValue_2 = Double.parseDouble(finalValue2);
                        }else{
                            finalValue_2 = 0.0;
                        }
                        if(finalValue_1 <= finalValue_2){
                            finalValue = finalValue_1;
                        }else{
                            finalValue = finalValue_2;
                        }
                        finalNewV = "0.0".equals(finalValue.toString()) ? "" : CommonUtils.removeZeros(finalValue.toString());
                    }else if("3".equals(baseCapacityRuleType.toString())){
                        //取当前值
                        List<String> valueList = new ArrayList<>();
                        if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                            for (String s : keyArr) {
                                //System.out.println("key：" + s);
                                // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                String currentValue = "";
                                for (Integer deviceResourceId : deviceResourceIdList) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                                valueList.add(currentValue);
                            }
                        }
                        String finalValue = "";
                        if(valueList.size() == 0){
                            finalValue = "";
                        }else{
                            finalValue = valueList.get(0);
                        }
                        finalNewV = finalValue;
                    }else if("4".equals(baseCapacityRuleType.toString())){
                        //取当前线体中所有该设备资源当前值 前两位判定大小 【同时取最小值】
                        String finalValue1 = "";
                        String finalValue2 = "";

                        // 按照 先循环 key 找出最大值
                        List<String> valueList = new ArrayList<>();
                        if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                            for (String s : keyArr) {
                                // 根据pcbaDeviceResourceId 和 key 值查询当前值
                                String currentValue = "";
                                for (Integer deviceResourceId : deviceResourceIdList) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                                valueList.add(currentValue);
                            }
                        }
                        if(valueList.size() == 0){
                            finalValue1 = "";
                        }else{
                            for (String s : valueList) {
                                // 取最大值
                                // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                if(CommonUtils.isNumeric(s)){
                                    if("".equals(finalValue1)){
                                        finalValue1 = s;
                                    }else{
                                        String ss = "";
                                        if(s.length() >= 2){
                                            ss = s.substring(0,2);
                                            if(Double.parseDouble(ss) <= Double.parseDouble(finalValue1.substring(0,2))){
                                                finalValue1 = s;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // 按照 先循环 设备资源id 找出最大值
                        List<String> valueList2 = new ArrayList<>();
                        for (Integer deviceResourceId : deviceResourceIdList) {
                            String currentValue = "";
                            if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                            }
                            valueList2.add(currentValue);
                        }
                        if(valueList2.size() == 0){
                            finalValue2 = "";
                        }else{
                            for (String s : valueList2) {
                                // 取最大值
                                // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                if(CommonUtils.isNumeric(s)){
                                    if("".equals(finalValue2)){
                                        finalValue2 = s;
                                    }else{
                                        String ss = "";
                                        if(s.length() >= 2){
                                            ss = s.substring(0,2);
                                            if(Double.parseDouble(ss) <= Double.parseDouble(finalValue2.substring(0,2))){
                                                finalValue2 = s;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // 比较 finalValue1 和 finalValue2 前2位 取最小
                        String finalValue_1 = "";
                        String finalValue_2 = "";
                        String finalValue = "";
                        if(finalValue1.length() >= 2 && CommonUtils.isNumeric(finalValue1.substring(0, 2))){
                            finalValue_1 = finalValue1;
                        }else{
                            finalValue_1 = "";
                        }
                        if(finalValue2.length() >= 2 && CommonUtils.isNumeric(finalValue2.substring(0, 2))){
                            finalValue_2 = finalValue2;
                        }else{
                            finalValue_2 = "";
                        }
                        if(!"".equals(finalValue_1) && !"".equals(finalValue_2)){
                            if(Double.parseDouble(finalValue1.substring(0, 2)) <= Double.parseDouble(finalValue2.substring(0, 2))){
                                finalValue = finalValue_1;
                            }else{
                                finalValue = finalValue_2;
                            }
                        }else{
                            if("".equals(finalValue_1)){
                                finalValue = finalValue_2;
                            }else{
                                finalValue = finalValue_1;
                            }
                        }
                        finalNewV = finalValue;
                    }else if("5".equals(baseCapacityRuleType.toString())){
                        //取当前线体中所有该设备资源当前值 前两位判定大小 【同时取最大值】
                        String finalValue1 = "";
                        String finalValue2 = "";

                        // 按照 先循环 key 找出最大值
                        List<String> valueList = new ArrayList<>();
                        if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                            String[] keyArr = pcbaDeviceParamKeys.split(",");
                            for (String s : keyArr) {
                                String currentValue = "";
                                for (Integer deviceResourceId : deviceResourceIdList) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                                valueList.add(currentValue);
                            }
                        }
                        if(valueList.size() == 0){
                            finalValue1 = "";
                        }else{
                            for (String s : valueList) {
                                // 取最大值
                                // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                if(CommonUtils.isNumeric(s)){
                                    if("".equals(finalValue1)){
                                        finalValue1 = s;
                                    }else{
                                        String ss = "";
                                        if(s.length() >= 2){
                                            ss = s.substring(0,2);
                                            if(Double.parseDouble(ss) >= Double.parseDouble(finalValue1.substring(0,2))){
                                                finalValue1 = s;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // 按照 先循环 设备资源id 找出最大值
                        List<String> valueList2 = new ArrayList<>();
                        for (Integer deviceResourceId : deviceResourceIdList) {
                            String currentValue = "";
                            if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                            }
                            valueList2.add(currentValue);
                        }
                        if(valueList2.size() == 0){
                            finalValue2 = "";
                        }else{
                            for (String s : valueList2) {
                                // 取最大值
                                // 先判断能不能转成数值，只判断能转成数值的，null 或者 “” 不参与判断
                                if(CommonUtils.isNumeric(s)){
                                    if("".equals(finalValue2)){
                                        finalValue2 = s;
                                    }else{
                                        String ss = "";
                                        if(s.length() >= 2){
                                            ss = s.substring(0,2);
                                            if(Double.parseDouble(ss) >= Double.parseDouble(finalValue2.substring(0,2))){
                                                finalValue2 = s;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // 比较 finalValue1 和 finalValue2 前2位 取最大
                        String finalValue_1 = "";
                        String finalValue_2 = "";
                        String finalValue = "";
                        if(finalValue1.length() >= 2 && CommonUtils.isNumeric(finalValue1.substring(0, 2))){
                            finalValue_1 = finalValue1;
                        }else{
                            finalValue_1 = "";
                        }
                        if(finalValue2.length() >= 2 && CommonUtils.isNumeric(finalValue2.substring(0, 2))){
                            finalValue_2 = finalValue2;
                        }else{
                            finalValue_2 = "";
                        }
                        if(!"".equals(finalValue_1) && !"".equals(finalValue_2)){
                            if(Double.parseDouble(finalValue1.substring(0, 2)) >= Double.parseDouble(finalValue2.substring(0, 2))){
                                finalValue = finalValue_1;
                            }else{
                                finalValue = finalValue_2;
                            }
                        }else{
                            if("".equals(finalValue_1)){
                                finalValue = finalValue_2;
                            }else{
                                finalValue = finalValue_1;
                            }
                        }
                        finalNewV = finalValue;
                    }else if("6".equals(baseCapacityRuleType.toString())){
                        // 按照设备资源循环 求 值的和
                        // 取和值
                        List<String> valueList = new ArrayList<>();
                        for (Integer deviceResourceId : deviceResourceIdList) {
                            String currentValue = "";
                            if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                            }
                            valueList.add(currentValue);
                        }
                        String finalValue = "";
                        Double finalValueDouble = 0.0;
                        if(valueList.size() == 0){
                            finalValue = "";
                        }else{
                            for (String s : valueList) {
                                // 取和
                                if(CommonUtils.isNumeric(s)){
                                    finalValueDouble = finalValueDouble + Double.parseDouble(s);
                                }
                            }
                            if(finalValueDouble > 0){
                                finalValue = CommonUtils.removeZeros(finalValueDouble.toString());
                            }
                        }
                        finalNewV = finalValue;
                    }else if("7".equals(baseCapacityRuleType.toString())){
                        // 只要有一台为”是“，则为是；全部”否“，则为”否“
                        List<String> valueList1 = new ArrayList<>();
                        for (Integer deviceResourceId : deviceResourceIdList) {
                            String currentValue = "";
                            if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                            }
                            valueList1.add(currentValue);
                        }

                        List<String> valueList2 = new ArrayList<>();
                        for (Integer deviceResourceId : deviceResourceIdList) {
                            String currentValue = "";
                            if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                            }
                            valueList2.add(currentValue);
                        }

                        String finalValue = "";
                        if(valueList1.contains("是") || valueList2.contains("是")){
                            finalValue = "是";
                        }else{
                            finalValue = "否";
                        }
                        finalNewV = finalValue;
                    }else if("8".equals(baseCapacityRuleType.toString())){
                        // 只要任意一台填写”有“，则为”有“
                        List<String> valueList1 = new ArrayList<>();
                        for (Integer deviceResourceId : deviceResourceIdList) {
                            String currentValue = "";
                            if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                            }
                            valueList1.add(currentValue);
                        }

                        List<String> valueList2 = new ArrayList<>();
                        for (Integer deviceResourceId : deviceResourceIdList) {
                            String currentValue = "";
                            if(pcbaDeviceParamKeys != null && !"".equals(pcbaDeviceParamKeys)){
                                String[] keyArr = pcbaDeviceParamKeys.split(",");
                                for (String s : keyArr) {
                                    PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam = pcbaDeviceRelatedDeviceParamDao.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(s, deviceResourceId);
                                    if(pcbaDeviceRelatedDeviceParam != null){
                                        currentValue = pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamValue();
                                        break;
                                    }
                                }
                            }
                            valueList2.add(currentValue);
                        }

                        String finalValue = "";
                        if(valueList1.contains("有") || valueList2.contains("有")){
                            finalValue = "有";
                        }else{
                            finalValue = "";
                        }
                        finalNewV = finalValue;
                    }else{
                        finalNewV = "NA";
                    }
                }else{
                    finalNewV = "NA";
                }
                Integer pcbaLineId = pcbaLine.getPcbaLineId();
                // 判断 线体的基线值是否和原来相等，不相等的话需要修改基线整线值
                LineBaseCapacityValue lineBaseCapacityValue = lineBaseCapacityValueDao.getLineBaseCapacityValueByKeyAndLineId(pcbaLineId, lineBaseParamKey);
                if(lineBaseCapacityValue != null){
                    if(!lineBaseCapacityValue.getLineBaseCapacityParamValue().equals(finalNewV)){
                        LineBaseCapacityValue updateLineBaseCapacityValue = new LineBaseCapacityValue();
                        updateLineBaseCapacityValue.setUpdateTime(d);
                        updateLineBaseCapacityValue.setLineBaseCapacityParamValue(finalNewV);
                        updateLineBaseCapacityValue.setLineBaseCapacityValueId(lineBaseCapacityValue.getLineBaseCapacityValueId());
                        lineBaseCapacityValueDao.updateLineBaseCapacityValue(updateLineBaseCapacityValue);
                    }
                }
            }
        }
    }
    *//**
     * 修改线体的宣称能力和实际能力，宣称能力和实际能力的认证状态均需要修改
     *//*
    public void changePcbaLineDeclareAndActualTechCapacity(
            List<PcbaLine> pcbaLineList,
            List<TechCapacityRule> techCapacityRuleList,
            Date d
    ){
        for (PcbaLine pcbaLine : pcbaLineList) {
            Integer pcbaLineId = pcbaLine.getPcbaLineId();
            for (TechCapacityRule techCapacityRule : techCapacityRuleList) {
                String baseCapacityParamKey = techCapacityRule.getBaseCapacityParamKey();
                String lineTechParamKey = techCapacityRule.getLineTechParamKey();
                Integer lineActualEqualDeclare = techCapacityRule.getActualEqualDeclare();
                Integer techCapacityRuleType = techCapacityRule.getTechCapacityRuleType();
                if(techCapacityRuleType == 1){
                    // 整线工艺宣称能力 = 基线能力
                    if(baseCapacityParamKey != null && !"".equals(baseCapacityParamKey)){
                        LineTechCapacityValue lineTechCapacityValue = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(pcbaLineId, lineTechParamKey);
                        LineBaseCapacityValue lineBaseCapacityValue = lineBaseCapacityValueDao.getLineBaseCapacityValueByKeyAndLineId(pcbaLineId, baseCapacityParamKey);
                        if(lineTechCapacityValue != null && lineBaseCapacityValue != null){
                            Integer lineTechCapacityValueId = lineTechCapacityValue.getLineTechCapacityValueId();
                            String lineTechCapacityParamKey = lineTechCapacityValue.getLineTechCapacityParamKey();
                            String lineTechCapacityParamValue = lineTechCapacityValue.getLineTechCapacityParamValue();
                            String lineBaseCapacityParamValue = lineBaseCapacityValue.getLineBaseCapacityParamValue();
                            if(!lineTechCapacityParamValue.equals(lineBaseCapacityParamValue)){
                                // update 工艺整线能力值
                                LineTechCapacityValue updateLineTechCapacityValue = new LineTechCapacityValue();
                                updateLineTechCapacityValue.setUpdateTime(d);
                                updateLineTechCapacityValue.setLineTechCapacityParamValue(lineBaseCapacityParamValue);
                                updateLineTechCapacityValue.setLineTechCapacityValueId(lineTechCapacityValueId);

                                // update 线体认证状态
                                PcbaLine updatePcbaLine = new PcbaLine();
                                updatePcbaLine.setUpdateTime(d);
                                updatePcbaLine.setPcbaLineId(pcbaLineId);
                                updatePcbaLine.setParamsStatusDeclare(4);

                                if(lineActualEqualDeclare == 1){
                                    updateLineTechCapacityValue.setLineTechCapacityParamValueActual(lineBaseCapacityParamValue);
                                    updatePcbaLine.setParamsStatusActual(4);
                                }
                                lineTechCapacityValueDao.updateLineTechCapacityValue(updateLineTechCapacityValue);
                                pcbaLineDao.updatePcbaLine(updatePcbaLine);
                            }
                        }
                    }
                }
            }
        }
    }
    *//**
     * 修改线体的实际能力，实际能力的认证状态均需要修改
     *//*
    public void changePcbaLineActualTechCapacity(Integer lineId,
                                                 Date d
    ){
        List<TechCapacityRule> techCapacityRuleList = techCapacityRuleDao.getAllTechCapacityRule(null, null, null);
        for (TechCapacityRule techCapacityRule : techCapacityRuleList) {
            if(techCapacityRule != null){
                Integer actualEqualDeclare = techCapacityRule.getActualEqualDeclare();
                String lineTechParamKey = techCapacityRule.getLineTechParamKey();
                if(actualEqualDeclare != null && actualEqualDeclare == 1){
                    LineTechCapacityValue lineTechCapacityValue = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(lineId, lineTechParamKey);
                    if(lineTechCapacityValue != null){
                        String lineTechCapacityParamValue = lineTechCapacityValue.getLineTechCapacityParamValue();
                        String lineTechCapacityParamValueActual = lineTechCapacityValue.getLineTechCapacityParamValueActual();
                        Integer lineTechCapacityValueId = lineTechCapacityValue.getLineTechCapacityValueId();
                        if(!lineTechCapacityParamValueActual.equals(lineTechCapacityParamValue)){
                            LineTechCapacityValue updateLineTechCapacityValue = new LineTechCapacityValue();
                            updateLineTechCapacityValue.setLineTechCapacityParamValueActual(lineTechCapacityParamValue);
                            updateLineTechCapacityValue.setLineTechCapacityValueId(lineTechCapacityValueId);
                            updateLineTechCapacityValue.setUpdateTime(d);
                            lineTechCapacityValueDao.updateLineTechCapacityValue(updateLineTechCapacityValue);

                            PcbaLine updatePcbaLine = new PcbaLine();
                            updatePcbaLine.setUpdateTime(d);
                            updatePcbaLine.setParamsStatusActual(4);
                            pcbaLineDao.updatePcbaLine(updatePcbaLine);
                        }
                    }
                }
            }
        }
    }*/
}
